PC Review


Reply
Thread Tools Rate Thread

calculate age between two dates

 
 
=?Utf-8?B?Q0JlYXZlcnM=?=
Guest
Posts: n/a
 
      30th Jul 2007
I need to calculate the age of someone at the time that a test was taken. I
need the age to show years and percentage of year (3.9 years old at time of
test).

I'm putting this formula in a form in Access 2003

My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])

StuDOB = Student date of birth
DateTest = Date test was taken

I get the correct years, but I can't get the percentage in months.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGFuaWVs?=
Guest
Posts: n/a
 
      30th Jul 2007
Take a look at

http://www.cardaconsultants.com/en/m...0000000011#age
--
Hope this helps,

Daniel P





"CBeavers" wrote:

> I need to calculate the age of someone at the time that a test was taken. I
> need the age to show years and percentage of year (3.9 years old at time of
> test).
>
> I'm putting this formula in a form in Access 2003
>
> My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
>
> StuDOB = Student date of birth
> DateTest = Date test was taken
>
> I get the correct years, but I can't get the percentage in months.
>

 
Reply With Quote
 
=?Utf-8?B?Q0JlYXZlcnM=?=
Guest
Posts: n/a
 
      30th Jul 2007
I'm using the expression builder in Access 2003. I tried that code and got an
error message that I was using invalid syntax

Thanks for your help though!
CBeavers

"Daniel" wrote:

> Take a look at
>
> http://www.cardaconsultants.com/en/m...0000000011#age
> --
> Hope this helps,
>
> Daniel P
>
>
>
>
>
> "CBeavers" wrote:
>
> > I need to calculate the age of someone at the time that a test was taken. I
> > need the age to show years and percentage of year (3.9 years old at time of
> > test).
> >
> > I'm putting this formula in a form in Access 2003
> >
> > My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
> >
> > StuDOB = Student date of birth
> > DateTest = Date test was taken
> >
> > I get the correct years, but I can't get the percentage in months.
> >

 
Reply With Quote
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      30th Jul 2007
This is the easiest age calculator I have come accross:

Public Function Age(Bdate, DateToday) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. Bdate > DateToday

Age = DateDiff("yyyy", Bdate, DateToday) - IIf(Format(Bdate, "mmdd") > _
Format(DateToday, "mmdd"), 1, 0)
End Function

--
Dave Hargis, Microsoft Access MVP


"CBeavers" wrote:

> I'm using the expression builder in Access 2003. I tried that code and got an
> error message that I was using invalid syntax
>
> Thanks for your help though!
> CBeavers
>
> "Daniel" wrote:
>
> > Take a look at
> >
> > http://www.cardaconsultants.com/en/m...0000000011#age
> > --
> > Hope this helps,
> >
> > Daniel P
> >
> >
> >
> >
> >
> > "CBeavers" wrote:
> >
> > > I need to calculate the age of someone at the time that a test was taken. I
> > > need the age to show years and percentage of year (3.9 years old at time of
> > > test).
> > >
> > > I'm putting this formula in a form in Access 2003
> > >
> > > My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
> > >
> > > StuDOB = Student date of birth
> > > DateTest = Date test was taken
> > >
> > > I get the correct years, but I can't get the percentage in months.
> > >

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      30th Jul 2007
On Mon, 30 Jul 2007 12:06:02 -0700, CBeavers
<(E-Mail Removed)> wrote:

>I need to calculate the age of someone at the time that a test was taken. I
>need the age to show years and percentage of year (3.9 years old at time of
>test).
>
>I'm putting this formula in a form in Access 2003
>
>My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
>
>StuDOB = Student date of birth
>DateTest = Date test was taken
>
>I get the correct years, but I can't get the percentage in months.


Is 3.9 three years and nine months? or 3 years and 349 days (0.9 years)? Your
phrase "percentage in months" is worrisome...

To get years and fractional years, accurate to +1 in the first decimal place
over the span of a century (by ignoring leap years), you can use

Round(DateDiff("d", [StuDOB], [DateTest]) / 365., 1)


John W. Vinson [MVP]
 
Reply With Quote
 
=?Utf-8?B?Q0JlYXZlcnM=?=
Guest
Posts: n/a
 
      31st Jul 2007
I'm wanting to show 3 years 9 months as 3.9. Is that possible? I tried the
following in the expression builder Access 2003, and it gave me an invalid
syntax error. What am I doing wrong?


=DateDiff("yyyy", [StuDOB], [DateTest]), Round(DateDiff("m",[StuDOB],
[DateTest]) / 12., 1)

"John W. Vinson" wrote:

> On Mon, 30 Jul 2007 12:06:02 -0700, CBeavers
> <(E-Mail Removed)> wrote:
>
> >I need to calculate the age of someone at the time that a test was taken. I
> >need the age to show years and percentage of year (3.9 years old at time of
> >test).
> >
> >I'm putting this formula in a form in Access 2003
> >
> >My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
> >
> >StuDOB = Student date of birth
> >DateTest = Date test was taken
> >
> >I get the correct years, but I can't get the percentage in months.

>
> Is 3.9 three years and nine months? or 3 years and 349 days (0.9 years)? Your
> phrase "percentage in months" is worrisome...
>
> To get years and fractional years, accurate to +1 in the first decimal place
> over the span of a century (by ignoring leap years), you can use
>
> Round(DateDiff("d", [StuDOB], [DateTest]) / 365., 1)
>
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
=?Utf-8?B?Q0JlYXZlcnM=?=
Guest
Posts: n/a
 
      31st Jul 2007
I'm putting this formula in a form in Access 2003 using the expression builder.

> > > > My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
> > > >
> > > > StuDOB = Student date of birth
> > > > DateTest = Date test was taken


The Expression builder wants the field names in brackets [].

I put your expression in as

DateDiff("yyyy",[StuDOB],[DateTest]) - If(Format([StuDOB], "mmdd")>_
Format([DateTest], "mmdd"), 1, 0)
End function

but it gave me a syntax error message.

Please advise!! Thank you so much for your help!!


"Klatuu" wrote:

> This is the easiest age calculator I have come accross:
>
> Public Function Age(Bdate, DateToday) As Integer
> ' Returns the Age in years between 2 dates
> ' Doesn't handle negative date ranges i.e. Bdate > DateToday
>
> Age = DateDiff("yyyy", Bdate, DateToday) - IIf(Format(Bdate, "mmdd") > _
> Format(DateToday, "mmdd"), 1, 0)
> End Function
>
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "CBeavers" wrote:
>
> > I'm using the expression builder in Access 2003. I tried that code and got an
> > error message that I was using invalid syntax
> >
> > Thanks for your help though!
> > CBeavers
> >
> > "Daniel" wrote:
> >
> > > Take a look at
> > >
> > > http://www.cardaconsultants.com/en/m...0000000011#age
> > > --
> > > Hope this helps,
> > >
> > > Daniel P
> > >
> > >
> > >
> > >
> > >
> > > "CBeavers" wrote:
> > >
> > > > I need to calculate the age of someone at the time that a test was taken. I
> > > > need the age to show years and percentage of year (3.9 years old at time of
> > > > test).
> > > >
> > > > I'm putting this formula in a form in Access 2003
> > > >
> > > > My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
> > > >
> > > > StuDOB = Student date of birth
> > > > DateTest = Date test was taken
> > > >
> > > > I get the correct years, but I can't get the percentage in months.
> > > >

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      31st Jul 2007
DateDiff("m", [StuDOB], [DateTest]) will give you the total number of months
between the two dates. To only get the "left over" months, you could use
DateDiff("m", [StuDOB], [DateTest]) Mod 12.

However, adding 9 as .9 can be a bit problematic. If you were only adding
values between 1 and 9, you'd divide by 10 and add it to the number of
years. However, since you can also have values of 10, 11, and 12, that
approach won't work. It would be easier if you'd accept 3.09 for 3 years, 9
months, because then you could use

=DateDiff("yyyy", [StuDOB], [DateTest]) + _
Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)

Otherwise, you'll need something like:

=DateDiff("yyyy", [StuDOB], [DateTest]) + _
IIf((DateDiff("m",[StuDOB], [DateTest]) mod 12) < 10,
Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 10, 1),
Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 100, 2))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"CBeavers" <(E-Mail Removed)> wrote in message
news9F14810-F5C5-414C-95EF-(E-Mail Removed)...
> I'm wanting to show 3 years 9 months as 3.9. Is that possible? I tried the
> following in the expression builder Access 2003, and it gave me an invalid
> syntax error. What am I doing wrong?
>
>
> =DateDiff("yyyy", [StuDOB], [DateTest]), Round(DateDiff("m",[StuDOB],
> [DateTest]) / 12., 1)
>
> "John W. Vinson" wrote:
>
>> On Mon, 30 Jul 2007 12:06:02 -0700, CBeavers
>> <(E-Mail Removed)> wrote:
>>
>> >I need to calculate the age of someone at the time that a test was
>> >taken. I
>> >need the age to show years and percentage of year (3.9 years old at time
>> >of
>> >test).
>> >
>> >I'm putting this formula in a form in Access 2003
>> >
>> >My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
>> >
>> >StuDOB = Student date of birth
>> >DateTest = Date test was taken
>> >
>> >I get the correct years, but I can't get the percentage in months.

>>
>> Is 3.9 three years and nine months? or 3 years and 349 days (0.9 years)?
>> Your
>> phrase "percentage in months" is worrisome...
>>
>> To get years and fractional years, accurate to +1 in the first decimal
>> place
>> over the span of a century (by ignoring leap years), you can use
>>
>> Round(DateDiff("d", [StuDOB], [DateTest]) / 365., 1)
>>
>>
>> John W. Vinson [MVP]
>>



 
Reply With Quote
 
=?Utf-8?B?Q0JlYXZlcnM=?=
Guest
Posts: n/a
 
      31st Jul 2007
I'm getting so close, but it's not quite right.

I am wanting to count up to 12 months.
I plugged 12/16/87 for the StuDOB (Student D.O.B) and 2/21/1991 for the
DateTest (Date of test)

But, I got back 3.98 instead of 3.02

=DateDiff("yyyy", [StuDOB], [DateTest]) + -
Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)

"Douglas J. Steele" wrote:

> DateDiff("m", [StuDOB], [DateTest]) will give you the total number of months
> between the two dates. To only get the "left over" months, you could use
> DateDiff("m", [StuDOB], [DateTest]) Mod 12.
>
> However, adding 9 as .9 can be a bit problematic. If you were only adding
> values between 1 and 9, you'd divide by 10 and add it to the number of
> years. However, since you can also have values of 10, 11, and 12, that
> approach won't work. It would be easier if you'd accept 3.09 for 3 years, 9
> months, because then you could use
>
> =DateDiff("yyyy", [StuDOB], [DateTest]) + _
> Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)
>
> Otherwise, you'll need something like:
>
> =DateDiff("yyyy", [StuDOB], [DateTest]) + _
> IIf((DateDiff("m",[StuDOB], [DateTest]) mod 12) < 10,
> Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 10, 1),
> Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 100, 2))
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "CBeavers" <(E-Mail Removed)> wrote in message
> news9F14810-F5C5-414C-95EF-(E-Mail Removed)...
> > I'm wanting to show 3 years 9 months as 3.9. Is that possible? I tried the
> > following in the expression builder Access 2003, and it gave me an invalid
> > syntax error. What am I doing wrong?
> >
> >
> > =DateDiff("yyyy", [StuDOB], [DateTest]), Round(DateDiff("m",[StuDOB],
> > [DateTest]) / 12., 1)
> >
> > "John W. Vinson" wrote:
> >
> >> On Mon, 30 Jul 2007 12:06:02 -0700, CBeavers
> >> <(E-Mail Removed)> wrote:
> >>
> >> >I need to calculate the age of someone at the time that a test was
> >> >taken. I
> >> >need the age to show years and percentage of year (3.9 years old at time
> >> >of
> >> >test).
> >> >
> >> >I'm putting this formula in a form in Access 2003
> >> >
> >> >My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
> >> >
> >> >StuDOB = Student date of birth
> >> >DateTest = Date test was taken
> >> >
> >> >I get the correct years, but I can't get the percentage in months.
> >>
> >> Is 3.9 three years and nine months? or 3 years and 349 days (0.9 years)?
> >> Your
> >> phrase "percentage in months" is worrisome...
> >>
> >> To get years and fractional years, accurate to +1 in the first decimal
> >> place
> >> over the span of a century (by ignoring leap years), you can use
> >>
> >> Round(DateDiff("d", [StuDOB], [DateTest]) / 365., 1)
> >>
> >>
> >> John W. Vinson [MVP]
> >>

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      31st Jul 2007
It looks as though you put a minus sign after the plus sign.

In what I had written, it was an underscore character (the line continuation
character). However, it does point out an issue with what I proposed, due to
how the DateDiff function works. When using yyyy as a parameter, DateDiff
returns how many year ends are passed. DateDiff("yyyy", #12/31/2006#,
#1/1/2007#) will return 1 year, despite the fact that it's only 1 day.

Try the following instead:

=(DateDiff("m", [StuDOB], [DateTest]) \ 12) + _
Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)

Note that's \, not /, in front of the 12 on the first line. If you're typing
it all on 1 line, ignore the underscore character.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"CBeavers" <(E-Mail Removed)> wrote in message
news:6A181DEC-1831-4A28-B616-(E-Mail Removed)...
> I'm getting so close, but it's not quite right.
>
> I am wanting to count up to 12 months.
> I plugged 12/16/87 for the StuDOB (Student D.O.B) and 2/21/1991 for the
> DateTest (Date of test)
>
> But, I got back 3.98 instead of 3.02
>
> =DateDiff("yyyy", [StuDOB], [DateTest]) + -
> Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)
>
> "Douglas J. Steele" wrote:
>
>> DateDiff("m", [StuDOB], [DateTest]) will give you the total number of
>> months
>> between the two dates. To only get the "left over" months, you could use
>> DateDiff("m", [StuDOB], [DateTest]) Mod 12.
>>
>> However, adding 9 as .9 can be a bit problematic. If you were only adding
>> values between 1 and 9, you'd divide by 10 and add it to the number of
>> years. However, since you can also have values of 10, 11, and 12, that
>> approach won't work. It would be easier if you'd accept 3.09 for 3 years,
>> 9
>> months, because then you could use
>>
>> =DateDiff("yyyy", [StuDOB], [DateTest]) + _
>> Round((DateDiff("m",[StuDOB], [DateTest]) mod 12) / 100., 2)
>>
>> Otherwise, you'll need something like:
>>
>> =DateDiff("yyyy", [StuDOB], [DateTest]) + _
>> IIf((DateDiff("m",[StuDOB], [DateTest]) mod 12) < 10,
>> Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 10, 1),
>> Round(DateDiff("m",[StuDOB], [DateTest]) mod 12 / 100, 2))
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "CBeavers" <(E-Mail Removed)> wrote in message
>> news9F14810-F5C5-414C-95EF-(E-Mail Removed)...
>> > I'm wanting to show 3 years 9 months as 3.9. Is that possible? I tried
>> > the
>> > following in the expression builder Access 2003, and it gave me an
>> > invalid
>> > syntax error. What am I doing wrong?
>> >
>> >
>> > =DateDiff("yyyy", [StuDOB], [DateTest]), Round(DateDiff("m",[StuDOB],
>> > [DateTest]) / 12., 1)
>> >
>> > "John W. Vinson" wrote:
>> >
>> >> On Mon, 30 Jul 2007 12:06:02 -0700, CBeavers
>> >> <(E-Mail Removed)> wrote:
>> >>
>> >> >I need to calculate the age of someone at the time that a test was
>> >> >taken. I
>> >> >need the age to show years and percentage of year (3.9 years old at
>> >> >time
>> >> >of
>> >> >test).
>> >> >
>> >> >I'm putting this formula in a form in Access 2003
>> >> >
>> >> >My current calculation is DateDiff("yyyy",[StuDOB],[DateTest])
>> >> >
>> >> >StuDOB = Student date of birth
>> >> >DateTest = Date test was taken
>> >> >
>> >> >I get the correct years, but I can't get the percentage in months.
>> >>
>> >> Is 3.9 three years and nine months? or 3 years and 349 days (0.9
>> >> years)?
>> >> Your
>> >> phrase "percentage in months" is worrisome...
>> >>
>> >> To get years and fractional years, accurate to +1 in the first decimal
>> >> place
>> >> over the span of a century (by ignoring leap years), you can use
>> >>
>> >> Round(DateDiff("d", [StuDOB], [DateTest]) / 365., 1)
>> >>
>> >>
>> >> John W. Vinson [MVP]
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate between two dates Cam Microsoft Access Queries 3 11th Sep 2009 07:14 PM
calculate dates lilbit27 Microsoft Access Forms 1 6th Jul 2007 01:23 AM
How do I calculate an age from 2 dates? =?Utf-8?B?VU1NWQ==?= Microsoft Excel Worksheet Functions 3 2nd Aug 2005 10:36 PM
calculate dates =?Utf-8?B?dGluYQ==?= Microsoft Access Getting Started 8 15th Jun 2005 08:14 PM
Calculating dates - Need to calculate years and months between source dates. jmw748 Microsoft Access Queries 2 7th Jan 2004 12:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.