Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Age to Years,Month,Day - Problem With
Message
De
12/09/2002 03:10:35
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
10/09/2002 17:35:27
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00699014
Message ID:
00699653
Vues:
18
>Try this:
>
>*************
>* AgeInYMD
>* Parameters :
>* date DateOfBirth,
>* date TargetDateToCalculateAge (If not passed date() assumed),
>*
>* return : Character - Age in YYYYMMDD format
>*************
>
>LPARAMETERS dBirthDate, dTargetDate
>IF parameters() < 1
> RETURN {}
>ENDIF
>IF empty(dTargetDate)
> dTargetDate = date()
>ENDIF
>
>nBirthYear = year(dBirthDate)
>nBirthMonth = month(dBirthDate)
>nBirthDay = day(dBirthDate)
>
>nCurYear = year(dTargetDate)
>nCurMonth = month(dTargetDate)
>nCurDay = day(dTargetDate)
>
>nLastMonth = IIF(nCurMonth = 12,1,nCurMonth-1)
>nDaysInMonth = IIF(INLIST(nLastMonth,1,3,5,7,8,10,12),31,;
> IIF(INLIST(nLastMonth,4,6,9,11),30,;
> IIF(INT(nCurYear/4)=0,28,29)))
>
>nHowManyYears = IIF(nCurMonth > nBirthMonth, nCurYear - nBirthYear, (nCurYear - nBirthYear) -1)
>nHowManyMonths = IIF(nCurMonth > nBirthMonth, nCurMonth-nBirthMonth, (12-nBirthMonth) + nCurMonth)
>nHowManyDays = IIF(nCurDay > nBirthDay , nCurDay-nBirthDay , (nDaysInMonth-nBirthDay)+nCurDay)
>
>lcReturn = [|]+ALLTRIM(STR(nHowManyYears))+[|]+ALLTRIM(STR(nHowManyMonths))+[|]+ALLTRIM(STR(nHowManyDays))+[|]
>
>return lcReturn
>
>
>mandy

Mandy,
A slight correction for leap year :

IIF((nCurYear%4=0 and nCurYear%100#0) or nCurYear%400=0,29,28)

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

Click here to load this message in the networking platform