1. Registered User
Join Date
Feb 2003
Posts
107

Hi there. I'm trying to do age calculations using the datediff function.
my if statement looks like this:

If ((DateDiff("d", Now(), birthDate) / 365) <= 65) Then

Failed test

End if
The datediff returns a negative number. How can I convert this to a positive number to represent a person's age? The above logic is passing a person who's age is over 100 because the datediff returns a "-" number.

2. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
One quick question - do you need your age calculation to be accurate? Because that ain't even close I am afraid *

* Even if we correct for the "-"

3. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
Tell you what - let's cut straight to an accurate function:
http://allenbrowne.com/func-08.html

EDIT - that implies I have tested it for accuracy - I have not but 1) It looks about right 2) Allen Browne is no thicky and he wouldn't post rubbish lightly.

4. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002
Originally Posted by pootle flump
yeah, as long as you don't mind stuff like this --
The following expression returns True if the person has not had their birthday this year:
Code:
`DateSerial(Year(Date), Month(DOB), Day(DOB)) > Date`
True equates to -1, so by adding this expression, Access subtracts one if the birthday hasn't occurred.
moi, i prefer to use an actual CASE construction, or alternatively an IIF, if, you know, in case it's access

5. Registered User
Join Date
Feb 2003
Posts
107
thanks guys.

6. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
Originally Posted by r937
yeah, as long as you don't mind stuff like this ......
Fair enough. Gotta admit I just googled - I couldn't be bothered going through my code library or (shudder) writing sumfink from scratch - I haven't lowered myself to that since Autumn 1997.

The Moral For The OP - have a google and see what you find.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•