Calculating Age

  • Thread starter Secret Squirrel
  • Start date
S

Secret Squirrel

I know how to calculate a persons age in years but how can I do it to also
get a decimal value of months? For example if a person was born 5/20/1970
based on today's date they would be 38.3.

Here's what I'm using to get the year:

=DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))
 
J

John Spencer

Take a look at
Try the "More Complete DateDiff Function" Graham Seach and Doug Steele wrote.

http://www.accessmvp.com/djsteele/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.

It should give you some ideas on how to do what you want.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
S

Secret Squirrel

Thanks! That works but all I really want is a decimal value instead of
spelling it out like that.

John Spencer said:
Take a look at
Try the "More Complete DateDiff Function" Graham Seach and Doug Steele wrote.

http://www.accessmvp.com/djsteele/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.

It should give you some ideas on how to do what you want.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Secret said:
I know how to calculate a persons age in years but how can I do it to also
get a decimal value of months? For example if a person was born 5/20/1970
based on today's date they would be 38.3.

Here's what I'm using to get the year:

=DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))
 
J

James A. Fortune

Secret said:
I know how to calculate a persons age in years but how can I do it to also
get a decimal value of months? For example if a person was born 5/20/1970
based on today's date they would be 38.3.

Here's what I'm using to get the year:

=DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))

Secret (or should I say Theekret :)),

In:

http://groups.google.com/group/microsoft.public.access/msg/a003152fa335dbe9

I show how to get the elapsed Year(s), Month(s) and Day(s) since a
person's birthday. Using those numbers you should be able to get the
decimal you want with as much precision as you want. Time can be
included as well. Do you need to consider leap years? Maybe DateDiff
with days divided by 365.24 will do. Post back if you need more help.

James A. Fortune
(e-mail address removed)
 
S

Secret Squirrel

Isn't there an easy way to just modify my current formula to get this decimal
value? I see what you're doing on your link but it's pretty much the same as
John posted. It spells out the words years/months/days. I don't want that. I
just want a decimal value of years and months. I don't really care about
days.



James A. Fortune said:
Secret said:
I know how to calculate a persons age in years but how can I do it to also
get a decimal value of months? For example if a person was born 5/20/1970
based on today's date they would be 38.3.

Here's what I'm using to get the year:

=DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))

Secret (or should I say Theekret :)),

In:

http://groups.google.com/group/microsoft.public.access/msg/a003152fa335dbe9

I show how to get the elapsed Year(s), Month(s) and Day(s) since a
person's birthday. Using those numbers you should be able to get the
decimal you want with as much precision as you want. Time can be
included as well. Do you need to consider leap years? Maybe DateDiff
with days divided by 365.24 will do. Post back if you need more help.

James A. Fortune
(e-mail address removed)
 
J

James A. Fortune

Secret said:
Isn't there an easy way to just modify my current formula to get this decimal
value? I see what you're doing on your link but it's pretty much the same as
John posted. It spells out the words years/months/days. I don't want that. I
just want a decimal value of years and months. I don't really care about
days.

Just take the days part off as well as the text for everything. Then
you have two expressions, one for years and one for elapsed months and
can use them to create your decimal.

Maybe you want:

<year expression> + Int(<month expression> * 10.0/ 12.0) / 10.0

That would take the number of elapsed months divided by 12 and chop it
at the tenth's place.

James A. Fortune
(e-mail address removed)
 
S

Steve Schapel

Squirrel,

This would probably be acceptably accurate:
Round(DateDiff("d",#5/20/1970#,Date())/365.24,1)
 
J

John Spencer

The idea was for you to look at the code and use parts of it to build
your own function.


UNTESTED but you might try the following to get the decimal portion of
the age:

((DateDiff("M",[BirthDate],Date()) +
Format([Birthdate],"mmdd")>Format(Date(),"mmdd")) Mod 12) / 12




'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


Secret said:
Thanks! That works but all I really want is a decimal value instead of
spelling it out like that.

John Spencer said:
Take a look at
Try the "More Complete DateDiff Function" Graham Seach and Doug Steele wrote.

http://www.accessmvp.com/djsteele/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.

It should give you some ideas on how to do what you want.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Secret said:
I know how to calculate a persons age in years but how can I do it to also
get a decimal value of months? For example if a person was born 5/20/1970
based on today's date they would be 38.3.

Here's what I'm using to get the year:

=DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))
 
P

Pete D.

every so often you have to go to the fridge and find a drink of your choice.
John Spencer said:
The idea was for you to look at the code and use parts of it to build your
own function.


UNTESTED but you might try the following to get the decimal portion of the
age:

((DateDiff("M",[BirthDate],Date()) +
Format([Birthdate],"mmdd")>Format(Date(),"mmdd")) Mod 12) / 12




'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


Secret said:
Thanks! That works but all I really want is a decimal value instead of
spelling it out like that.

John Spencer said:
Take a look at
Try the "More Complete DateDiff Function" Graham Seach and Doug Steele
wrote.

http://www.accessmvp.com/djsteele/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.

It should give you some ideas on how to do what you want.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Secret Squirrel wrote:
I know how to calculate a persons age in years but how can I do it to
also get a decimal value of months? For example if a person was born
5/20/1970 based on today's date they would be 38.3.
Here's what I'm using to get the year:

=DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))
 

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