Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dates
Message
De
04/03/2003 20:14:34
 
 
À
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:
00761294
Vues:
16
This is a function that I wrote to return a date from a passed value of any data type. Returns a blank date for logical or unknown values that cannot be converted to a date.
FUNCTION make_date
 LPARAMETERS m.lvar2convert
 LOCAL m.lmdreturndate,m.lcSetDate,m.lcyear,m.lcmonth,m.lcday
 m.lmdreturndate = {}
 DO CASE
  CASE TYPE("m.lVar2convert") = "D"
   m.lmdreturndate = m.lvar2convert
  CASE TYPE("m.lVar2convert") = "T"
   m.lmdreturndate = TTOD(M.lvar2convert)
  CASE TYPE("m.lVar2convert") = "N"
   *!* assumes julian day number
   m.lmdreturndate = CTOD(SYS(10,m.lvar2convert))
  CASE TYPE("m.lVar2convert") <> "C"

  CASE "/"$m.lvar2convert .OR. "-"$m.lvar2convert .OR. "."$m.lvar2convert
   *!* assumes date is in ctod format
   m.lmdreturndate = CTOD(m.lvar2convert)
  CASE LEN(trim(m.lvar2convert)) >= 6 and val(m.lvar2convert) > 0
    *!* assumes YYYYMMDD format or YYMMDD format
   m.lvar2convert = PADL(m.lvar2convert,8," ")
   m.lcyear = alltrim(SUBSTR(m.lvar2convert,1,4))
   m.lcmonth = alltrim(SUBSTR(m.lvar2convert,5,2))
   m.lcday = alltrim(SUBSTR(m.lvar2convert,7))
   m.lcSetDate = set("date")
   DO CASE
    CASE m.lcSetDate = "AMERICAN" .OR. SET("date") = "MDY"
     m.lmdreturndate = CTOD(m.lcmonth+"/"+m.lcday+"/"+m.lcyear)
    CASE m.lcSetDate = "USA"
     m.lmdreturndate = CTOD(m.lcmonth+"-"+m.lcday+"-"+m.lcyear)
    CASE m.lcSetDate = "ANSI"
     m.lmdreturndate = CTOD(m.lcyear+"."+m.lcmonth+"."+m.lcday)
    CASE m.lcSetDate = "BRITISH" .OR. m.lcSetDate = "FRENCH" .OR. m.lcSetDate = "MDY"
     m.lmdreturndate = CTOD(m.lcday+"/"+m.lcmonth+"/"+m.lcyear)
    CASE m.lcSetDate = "GERMAN"
     m.lmdreturndate = CTOD(m.lcday+"."+m.lcmonth+"/"+m.lcyear)
    CASE m.lcSetDate = "ITALIAN"
     m.lmdreturndate = CTOD(m.lcday+"-"+m.lcmonth+"-"+m.lcyear)
    CASE m.lcSetDate = "JAPAN" OR m.lcSetDate = "YMD"
     m.lmdreturndate = CTOD(m.lcyear+"/"+m.lcmonth+"/"+m.lcday)
   ENDCASE
 ENDCASE
 RETURN  m.lmdreturndate
HTH

>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform