Age in yrs,months and days

varunmathur

Registered User.
Local time
Today, 04:41
Joined
Feb 3, 2001
Messages
68
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
 
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 ?
 

Users who are viewing this thread

Back
Top Bottom