Hi,
I downloaded a function from the Microsoft Knowledge base to calculate a persons age as at the current date based on DOB. The function is as follows:
Function Age(varBirthDat e As Variant) As Integer
Dim varAge As Variant
If IsNull(varBirth Date) Then Age = 0: Exit Function
varAge = DateDiff("yyyy" , varBirthDate, Now)
If Date < DateSerial(Year (Now), Month(varBirthD ate), Day(varBirthDat e)) Then
varAge = varAge - 1
End If
Age = CInt(varAge)
End Function
I've tested it in the VB immediate window (Access 2K) by entering
?Age(#17/12/1975#)
This returns 30 - correct, as at today's date - 02/11/2006. However if I enter
?Age(#10/12/1975#), it returns 31. The only reason for this that I can think of is that the date format is being transposed into MM/DD/YYYY format. I've been trying to correct this by formatting the dates using the format function, converting all of the dates to YYYY-MM-DD format, but it still isn't working. I would really appreciate some help on this! Thanks.
I downloaded a function from the Microsoft Knowledge base to calculate a persons age as at the current date based on DOB. The function is as follows:
Function Age(varBirthDat e As Variant) As Integer
Dim varAge As Variant
If IsNull(varBirth Date) Then Age = 0: Exit Function
varAge = DateDiff("yyyy" , varBirthDate, Now)
If Date < DateSerial(Year (Now), Month(varBirthD ate), Day(varBirthDat e)) Then
varAge = varAge - 1
End If
Age = CInt(varAge)
End Function
I've tested it in the VB immediate window (Access 2K) by entering
?Age(#17/12/1975#)
This returns 30 - correct, as at today's date - 02/11/2006. However if I enter
?Age(#10/12/1975#), it returns 31. The only reason for this that I can think of is that the date format is being transposed into MM/DD/YYYY format. I've been trying to correct this by formatting the dates using the format function, converting all of the dates to YYYY-MM-DD format, but it still isn't working. I would really appreciate some help on this! Thanks.
Comment