[AccessD] Date Diff Help It cant be this hard

Arthur Fuller artful at rogers.com
Mon Jan 9 10:28:20 CST 2006


Here is a solution for you. You have stumbled upon a couple of croquet hoops
in date calculations, but here is a solution for you. First, using my
birthday as the value (rather than your control name), look at these
results:
? datediff("yyyy", #11/15/1947#, Date())
 59 
Which is wrong: I am 58 not 59: the problem is that the above examines only
the year.
? datediff("d", #11/15/1947#, Date())
 21240 
Which correctly returns the number of days between my birthdate and today.
? 21240 / 365.26
 58.1503586486339
This divides the number of days by the number of days in a year (the .26 is
for leap years and handles them correctly).
Now just Int() that value and you get the correct number of years. So,
ungainly as it is, the formula becomes:
? Int(DateDiff("d", #11/15/1947#, Date())/365.26)
There may be a simpler and foolproof way, but until someone presents it, you
can reliably use this. I would suggest creating a function AgeInYears() into
which you pass the DateOfBirth. Then when someone presents a simpler way to
do it, you can just change the content of the function.
HTH,
Arthur





More information about the AccessD mailing list