Re: Calculating Age

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Graham R Seach (gseach_at_NOSPAMpacificdb.com.au)
Date: 08/06/04


Date: Fri, 6 Aug 2004 14:19:29 +1000

When trying to calculate anniversaries, DateDiff is prone to errors, simply
because of the way it works. Unless you take into account the way DateDiff
works, you can end up being a year off.

Perhaps the following functions can help:
    http://www.pacificdb.com.au/MVP/Code/Age1.htm
    http://www.pacificdb.com.au/MVP/Code/Age2.htm
    http://www.pacificdb.com.au/MVP/Code/Diff2Dates.htm

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html

"Mark" <anonymous@discussions.microsoft.com> wrote in message
news:06bb01c47add$e1004970$a301280a@phx.gbl...
> This is quite a crude way of calculating an age. If you
> select the Access Help menu and type Datediff there may be
> an example and description of how to use it. It's not
> strictly code but a built-in function of Access.
>
> Just a word of warning - The DateDiff function is best
> used to show the number of days between two dates. I
> didn't realise you were using it for such a specific task.
> If you enter a date of birth of 01/10/2003 you will see
> the answer is 1 year (obviously not correct) because the
> calculation uses a type of rounding.
>
> To calculate the number of months, change the formula to
>
> =DateDiff("m",[DOB],Now())
>
>
> To calculate the number of days, change it to
>
> =DateDiff("y",[DOB],Now())
>
>
> It may be better to work with months rather than years for
> your requirements.
>
> Hope this helps
>
>
>
>
> >-----Original Message-----
> >Great!!! Thanks Mark,
> >
> >Is it possible to take it one step further where if say
> the DOB i13-06-03
> >that the forula in the age field would bring up 1/1 for 1
> year and 1 month.
> >I didnt realise it had to be exact to the year and
> month. Its for show cats
> >and its inmortant that its calculated to the month as
> this depends on what
> >class they enter depending on their aage by year and
> month.
> >
> >thanks
> >Julie
> >
> >
> >"Mark" <anonymous@discussions.microsoft.com> wrote in
> message
> >news:062b01c47abf$ca5dbea0$a501280a@phx.gbl...
> >> In the field you want to calculate the Age, bring up the
> >> field properties, select the data tab and in the Control
> >> Source enter
> >>
> >> =DateDiff("yyyy",[DOB],Now())
> >>
> >> Where [DOB] is your date of birth field
> >>
> >>
> >> >-----Original Message-----
> >> >If I have the Date of Birth in a field, what expresion
> >> can I use in another
> >> >field, say AGE field, that would calculate the actual
> age
> >> automatically?
> >> >
> >> >Like DOB field has 29/06/66 in it so Age field becomes
> 38
> >> calculated
> >> >automatically when DOB is entered.
> >> >
> >> >thanks
> >> >Julie
> >> >
> >> >
> >> >.
> >> >
> >
> >
> >.
> >



Relevant Pages

  • Re: Calculate Time Difference
    ... Use DateDiff to calculate the different in minutes, ... Doug Steele, Microsoft Access MVP ... > calculates the amount of time elapsed between the two, ...
    (microsoft.public.access.formscoding)
  • Re: Calculating Total Hours
    ... Being that you are talking about calculating the differences between ... better off using the datediff function rather then the sum function, ... The datediff will tell you how many have passed between ... Anthony Moore ...
    (microsoft.public.access.forms)
  • RE: What is an automation object error?
    ... This is really identical to calculating a person's age, ... The problem is that DateDiff() using the ... Answers/posts based on Access 2000/2003 ...
    (microsoft.public.access.gettingstarted)
  • Re: Windows Sharepoint Services
    ... DateDiff can be used for calculating more than just days. ... "10 - total time". ... It would be help ful for me if i receive the reply ASAP. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Strange Behaviors
    ... > about converting it. ... I've used about 3 different ways of calculating ... > the difference, including: DateDiff, ... > depending on which calculation I use. ...
    (microsoft.public.dotnet.languages.vb)