Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Not my date type
Message
De
29/03/2014 13:41:15
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
29/03/2014 11:58:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01597645
Message ID:
01597657
Vues:
54
>>>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform