this is basically how you would do it (I believe "now()" is used for the current date):
if you have a textbox, say: "text1" and your birthday is "01/01/1980"
datediff("yyyy", text1.text,now)
or you can have a look here:
http://www.mvps.org/access/datetime/date0001.htm
NOTE: I mentioned that this was "basically" how you do this. I included the link which contains several functions to do this correctly...
2007-03-17 07:03:11
·
answer #1
·
answered by Dilbert 3
·
0⤊
0⤋
It's not as simple as subtracting the current date from the birthday.
If today is 3/17/2007 and someone was born on 2/2/2001, that person is 6 years old. If the person was born on 5/5/2001, that person is 5 years old.
The DateDiff function does not check this - it simply returns the difference in years 2007 - 2001, always is 6, regardless of the month/day part. You have to account for that.
Also, it's not as simple as just finding the number of days and dividing by 365 because of leap years. The normal way to do this as follows (this is in vba, which is supported in access, you could tweak it to return in SQL)
Function GetAge(dob as Date)
Dim y as Integer
y = DateDiff("yyyy", dob, Now)
If DateAdd("yyyy", y, d) > Now Then
y = y - 1 'if their birthday hasn't come yet, don't count a year
End If
Return y
End Function
2007-03-17 14:08:44
·
answer #2
·
answered by vbslinger 2
·
0⤊
0⤋
Just like you would if you were doing it on paper.
If I told you my DOB was 03/17/2006, you'd subtract from the current date.
The current date in Access is date()
2007-03-17 12:33:01
·
answer #3
·
answered by Vegan 7
·
0⤊
1⤋