Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dates
Message
De
05/03/2003 05:23:50
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/03/2003 17:47:51
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: Dates
Divers
Thread ID:
00761251
Message ID:
00761395
Vues:
29
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform