Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Not my date type
Message
From
29/03/2014 13:41:15
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
29/03/2014 11:58:04
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01597645
Message ID:
01597657
Views:
53
>>>Hi All,
>>>
>>>Is there a better, or shall I say more elegant, way of extracting the numeric values from a date-formatted ("03/27/2014") text string than the following:
>>>
>>>lnmon=val(left(alltrim(this.text),2))
>>>lnyear=val(right(alltrim(this.text),4))
>>>lnday=val(substr(alltrim(this.text),4,2))
>>>lddate=date(lnyear,lnmon,lnday)
>>>
>>
>>I'll ask the obvious - have you tried CTOD(this.text)?
>
>
>CTOD() can do it as well but runs a risk of ambiguous date values (see the help). Using the DATE() function is safer because you need to specify the year, month and day specifically.

Chopping the string manually (as above) assumes ddmmyyyy. It doesn't know if there may be mmddyyyy dates in there, so the risk is the same.

At least, ctod() will return an empty date and won't error out on impossible values.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform