View Full Version : Age in yrs,months and days


varunmathur
03-11-2002, 06:16 AM
Hi
I need to calculate the age of student in years ,months and days as on a particular date; I manage to get the years and months part correctly but the days do not calculate correctly.
Any help would be appreciated.
varun

KKilfoil
03-11-2002, 06:39 AM
have you looked at: http://www.access-programmers.co.uk/ubb/Forum3/HTML/002475.html

araskas
03-11-2002, 06:48 AM
You can use the following function to get the age. You can replace the function by a lot of IIF statements if you want to.
If you know how to use VBA you can easily code this.
Otherwise also just open a new module and paste the following code in the module.


Public Function GetAge(dteDOB As Variant, dteRecd As Variant)
If IsDate(dteDOB) And IsDate(dteRecd) Then
If (DatePart("m", dteDOB) = DatePart("m", dteRecd) _
And _
DatePart("d", dteDOB) > DatePart("d", dteRecd) _
) Or _
DatePart("m", dteDOB) > DatePart("m", dteRecd) Then
GetAge = DateDiff("yyyy", dteDOB, dteRecd) - 1
Else
GetAge = DateDiff("yyyy", dteDOB, dteRecd)
End If
Else
GetAge = Null
End If

End Function

In your query code as below
SELECT Age: GetAge([MyTABLE]![DOB],date())
FROM MYTABLE ;
Post back if you have nay questions. By the way are you Amit Varun Mathur of DehraDoon, India ?

varunmathur
03-13-2002, 04:10 AM
Hi
Thanks the code worked just fine.
varun