Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Subtracting Dates
Message
De
23/11/1999 22:38:19
 
 
À
23/11/1999 13:52:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00294459
Message ID:
00294800
Vues:
28
>>>I can't get my dates to subtract correctly. I keep getting huge numbers. I want to subtract the system date with a birth date to get an age for that person. I am doing this in a SQL statement.
>>>
>>>select student.studentid, student.lname, date() - student.bdate as age
>>>from student into cursor clage
>>>
>>>My date format is in mdy. I get numbers like 7518. How come this is happening?
>>>
>>>Thanks in advance,
>>>Tyler G.
>>
>>(year(date())-year(student.bdate)-iif(student.bdate>date(),1,0)) as AGE
>
>How could the student.bdate be greater than DATE() ? Don't you mean ...IIF(MONTH(student.bdate)>MONTH(DATE()),1,0)) ... but even that is an approximation.

You are right, I quickly stole this code from a function I had... I missed this when I posted. In the function I actually use a date which is the passed date converted to this year, so basically, if you BirthDay for the current year hadn't passed yet it would show that you were the correct age.

This code gets kind unwildy as an expression, but it is still doable... Using my age funtion would be better:
*Function AgeInYears
lparam ldBirthDate

Assert vartype( ldBirthDate ) == "D" Message "Must pass variable type DATE!"
Assert ldBirthDate <= date() Message "Passed BirthDate can not be a future date."

local ldAnniversary

ldAnniversary = date( year(Date()),month(ldBirthDate),day(ldBirthDate) )

return year(date())-year(ldBirthDate)-iif(ldAnniversary>date(),1,0)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform