Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert character to date
Message
From
17/11/2002 02:04:38
 
 
To
17/11/2002 01:38:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00723600
Message ID:
00723605
Views:
7
>Hi,
>Anybody using FTPx from Mabry?
>I need to convert the date returned ("Nov 11 12:10:10 PM") by GetDirList() to VFP date data type. Any ideas?
>
>I tried to use CTOD() but it return empty date value.
* Function Char2Date
LPARAMETERS ;
	tcDateTime

LOCAL ;
	lcMonth, ;
	lcDayNumber, ;
	lcMonthNumber, ;
	lcYearNumber

* Need to parse the string and convert character month to numeric:
lcMonth = UPPER(SUBSTR(tcDateTime, 1, 3))

DO CASE
CASE lcMonth = "JAN"
	lcMonthNumber = "01"

CASE lcMonth = "FEB"
	lcMonthNumber = "02"

CASE lcMonth = "MAR"
	lcMonthNumber = "03"

CASE lcMonth = "APR"
	lcMonthNumber = "04"

CASE lcMonth = "MAY"
	lcMonthNumber = "05"

CASE lcMonth = "JUN"
	lcMonthNumber = "06"

CASE lcMonth = "JUL"
	lcMonthNumber = "07"

CASE lcMonth = "AUG"
	lcMonthNumber = "08"

CASE lcMonth = "SEP"
	lcMonthNumber = "09"

CASE lcMonth = "OCT"
	lcMonthNumber = "10"

CASE lcMonth = "NOV"
	lcMonthNumber = "11"

CASE lcMonth = "DEC"
	lcMonthNumber = "12"

ENDCASE

* Assume current year:
lcYearNumber = LTRIM(STR(YEAR(DATE())))

* Extract day:
* This is tricky if the return value has only a single digit for day # less than 10:
* To handle this, we'll always take the 5th and 6th characters. If the 6th is a space,
* the TRIM() will get rid of it.
* We also want values < 10 to be left padded with a zero:
lcDayNumber = PADL(TRIM(SUBSTR(tcDateTime, 5, 2)), 2, "0")

* Create and evaluate unambiguous date as the return value:
RETURN EVALUATE("{^" + lcYearNumber + "-" + lcMonthNumber + "-" + lcDayNumber + "}")
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform