Calculating dates - Need to calculate years and months between source dates.

J

jmw748

I'm a newbie to Access, so I'm not familiar with SQL yet. I need t
calculate the time period between a birthdate (Short Date Format) an
Now()). As DateDiff only calculates in time intervals of years, month
etc, I can't get Access to express the person's age in years an
months. Any help would be appreciated
 
J

jmw748

I have just found a thread from a previous post after some searching
I'll try the solution:
Age=DateDiff("yyyy", [Bdate], Now())+ _
Int( Format(now(), "mmdd") < Format( [Bdate], "mmdd")
and see if it works.
Thanks.
Ji
 
J

John Spencer (MVP)

Try the "More Complete DateDiff Function" Graham Seach and Doug Steele wrote.
http://members.rogers.com/douglas.j.steele/Diff2Dates.html

You specify how you want the difference between two date/times to be calculated
by providing which of ymdhns (for years, months, days, hours, minutes and
seconds) you want calculated.

For example:

?Diff2Dates("y", #06/01/1998#, #06/26/2002#)
4 years
?Diff2Dates("ymd", #06/01/1998#, #06/26/2002#)
4 years 25 days
?Diff2Dates("ymd", #06/01/1998#, #06/26/2002#, True)
4 years 0 months 25 days
?Diff2Dates("d", #06/01/1998#, #06/26/2002#)
1486 days

?Diff2Dates("h", #01/25/2002 01:23:01#, #01/26/2002 20:10:34#)
42 hours
?Diff2Dates("hns", #01/25/2002 01:23:01#, #01/26/2002 20:10:34#)
42 hours 47 minutes 33 seconds
?Diff2Dates("dhns", #01/25/2002 01:23:01#, #01/26/2002 20:10:34#)
1 day 18 hours 47 minutes 33 seconds

?Diff2Dates("ymd",#12/31/1999#,#1/1/2000#)
1 day
?Diff2Dates("ymd",#1/1/2000#,#12/31/1999#)
-1 day
?Diff2Dates("ymd",#1/1/2000#,#1/2/2000#)
1 day
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top