E
Edwin Huellstrounk
I am trying to set up access to calculate ages. Does anyone have an idea on
how to do this?
how to do this?
I am trying to set up access to calculate ages. Does anyone have an idea on
how to do this?
=BAge: Int((DateDiff("d",[Birthdate],Now())/365.25))
Where [birthdate] is a text field and [bAge] is a second column in a query
John said:On Tue, 29 Nov 2005 11:00:18 -0800, Edwin Huellstrounk <Edwin
I am trying to set up access to calculate ages. Does anyone have an
idea on how to do this?
You should not store the age anywhere - if you do, it will be wrong
next year anyway.
Store the DOB (Date Of Birth) field in a Date/Time field and use a
calculated field in a Query:
Age: DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)
The IIF function corrects the age if the birthdate has not yet arrived
this year.
John W. Vinson[MVP]
=DateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))
Same method, just a different syntax![]()
John said:=DateDiff("yyyy",[Birthdate],Now())+Int(Format(Now(),"mmdd")<Format([Birthdate],"mmdd"))
Same method, just a different syntax![]()
I used to, but someone pointed out that True is -1 in JET, +1 in
SQL/Server - so it limits the validity!
Works just fine in Access though and is likely a bit quicker, too.
It wouldn't matter since Int() would return 1 for 1 and -1 wouldn't it?
![]()
John said:Nope. Abs() would, but Int() just truncates any fractional part:
?int(-1)
-1
?int(-1.1)
-2
?int(-0.9)
-1