Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is best way to calculate age
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01155605
Message ID:
01155686
Vues:
32
>>I never need to calculate ages, but here what I invent :-)) (I hate endless loops)
>>
>>ldBegin = DATE(1965, 4, 26)
>>ldEnd   = DATE()
>>STORE 0 TO lnYear, lnMonhts, lnDays
>>DO WHILE .t.
>>   DO CASE
>>      CASE GOMONTH(ldBegin,12) <= ldEnd
>>           lnYear = lnYear + 1
>>           ldBegin = GOMONTH(ldBegin, 12)
>>      CASE GOMONTH(ldBegin,1) <= ldEnd
>>           lnMonhts = lnMonhts + 1
>>           ldBegin  = GOMONTH(ldBegin, 1)
>>      CASE ldBegin            < ldEnd
>>           lnDays  = lnDays  + 1
>>           ldBegin = ldBegin + 1
>>   OTHERWISE
>>           EXIT
>>   ENDCASE
>>ENDDO
>>? lnYear, lnMonhts, lndays
>>
>>Of couse there is no checking for valid date period and no error handling at all. Also not well tested :-)))
>
>The first very serious problem this code has is lnMonths is spelled wrongly <g>
>
>Add a back date calculation to your code to see, if the dates match.


Too much beer :o))))

Here the corrected code :-)
ldBegin = DATE(2006, 4, 26)
ldEnd   = DATE()
STORE 0 TO lnYear, lnMonths, lnDays
DO WHILE .t.
   DO CASE
      CASE GOMONTH(ldBegin,12) <= ldEnd
           lnYear = lnYear + 1
           ldBegin = GOMONTH(ldBegin, 12)
      CASE GOMONTH(ldBegin,1) <= ldEnd
           lnMonths = lnMonths + 1
           ldBegin  = GOMONTH(ldBegin, 1)
      CASE ldBegin            < ldEnd
           lnDays  = lnDays  + 1
           ldBegin = ldBegin + 1 
   OTHERWISE
           EXIT 
   ENDCASE
ENDDO
? lnYear, lnMonths, lndays
? GOMONTH(DATE(),(-lnYear*12)-lnMonths)-lndays+1
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform