Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dates
Message
De
05/03/2003 10:52:44
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
05/03/2003 05:23:50
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: Dates
Divers
Thread ID:
00761251
Message ID:
00761515
Vues:
19
Hi Çetin

That works pretty well. Ambiguous dates are a problem, but your code is handling many kinds of ambiguity. It's not possible to deal with the date being entered as 12/10/1965 December 10, 1965 when the user meant to enter 10/12/1965.

Thanks!

>>Hi All
>>
>>I'm looking for a piece of code that can return a valid date given a variety of strings that may be dates. 19980216 returns 02/16/1998 and 2/12/94 returns 02/12/1994 etc.
>>
>>Any help would be appreciated.
>>
>>Thanks
>
>Mike,
>Ambigious dates are always a problem. Thinking it wouldn't be a problem :
>
>function Str2Date
>lparameters tcStr
>local ldRetVal, lcFormatStr
>if chrtran(tcStr,'/-.','')==tcStr && No date separators
>  if !inlist(len(tcStr),8,6) && Else too much ambigious
>    return {}
>  endif
>  lcFormatStr = padl('99/99/99',len(tcStr)+2,'9')
>  ldRetVal = ctod(transform(tcStr,'@R ^'+lcFormatStr)) && Try strict first
>  if empty(ldRetVal) && Try putting separators
>    ldRetVal = Str2Ctod(transform(tcStr,'@R '+lcFormatStr))
>    if empty(ldRetVal)
>      ldRetVal = Str2Ctod(transform(tcStr,'@R '+;
>           padr('99/99/99',len(tcStr)+2,'9')))
>    endif
>  endif
>else
>  ldRetVal = Str2Ctod(tcStr)
>endif
>return ldRetVal
>
>function Str2Ctod
>lparameters tcStr
>local lcDateSet, ldRetVal
>if !empty(ctod(tcStr))
>  return ctod(tcStr)
>endif
>lcDateSet = set('date')
>set date mdy && For US this one is first to try
>ldRetVal = ctod(tcStr)
>if empty(ldRetVal)
>  set date dmy
>  ldRetVal = ctod(tcStr)
>  if empty(ldRetVal)
>    set date ymd
>    ldRetVal = ctod(tcStr)
>  endif
>endif
>set date to &lcDateSet
>return ldRetVal
>
Cetin
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform