January 19, 200520 yr 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?
January 19, 200520 yr 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 ) )
January 19, 200520 yr Author 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.
Create an account or sign in to comment