nutthick Posted January 19, 2005 Posted January 19, 2005 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?
RalphL Posted January 19, 2005 Posted January 19, 2005 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 ) )
nutthick Posted January 19, 2005 Author Posted January 19, 2005 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.
Recommended Posts
This topic is 7317 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 accountSign in
Already have an account? Sign in here.
Sign In Now