Jump to content
Server Maintenance This Week. ×

Show Age in Days Months and Years


This topic is 7037 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I know this is covering old ground and I've checked out other posts, but still can't figure it out. I need to calculate someones age in days months and years. I have a date of birth (DOB) and an Age field. If I just calculate Age something like

Get(CurrentDate) - DOB

everything is fine as long as I store the result as a number. If I store as a date, the year part of the calcuation gets screwed up. Anything less than 12 months old shows 1 in the year. How do I get this to work correctly?

Link to comment
Share on other sites

First let me say that this sort of a meaningless calculation, a month can be 28 to 31 long. A year can be 365 or 366 days.

I have not found a calculation that I trust. Most of them fail when the birthday is the 31st and the current month has 30 or less days.

The following is the best I have seen, it was developed by Jason L. DeLooze:

Year = Case(

not IsEmpty(Test_Date) and not IsEmpty(Birthday) and (Test_Date >= Birthday) ;

Year(Test_Date) - Year(Birthday) - ( Test_Date < Date( Month(Birthday) ; Day(Birthday) ; Year(Test_Date) ) )

)

Month = Case(

not IsEmpty(Test_Date) and not IsEmpty(Birthday) and (Test_Date >= Birthday) ;

Mod( Month(Test_Date) - Month(Birthday) + 12 - ( Day(Test_Date) < Day(Birthday) ) ; 12 )

)

Day = Case(

not IsEmpty(Test_Date) and not IsEmpty(Birthday) and (Test_Date >= Birthday) ;

Case(

Day(Test_Date) >= Day(Birthday) ; Day(Test_Date) - Day(Birthday) ;

Date( Month(Birthday) + 1 ; 1 ; Year(Birthday) ) - Birthday + Day(Test_Date) - 1

)

)

Link to comment
Share on other sites

Thanks RalphL. I understand when you say it's meaningless, but everything is relative. My user just wants something that is roughly correct to read out loud. Any maths work will be done by other methods.

The formulas you gave me worked perfectly, thanks a lot.

Link to comment
Share on other sites

This topic is 7037 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.