October 16, 201312 yr I have the "date_of_birth" field and the "date_of_death" field I would like to calculate the current age, which is easy if the person is alive by using the Get CurrentDate function; however, if the person is dead, how should the value "date_of_death" field be used in the calculation to replace the CurrentDate value Thanks.
October 16, 201312 yr Try = Let ( date_of_calc = Case ( date_of_death ; date_of_death ; Get ( CurrentDate ) ) ; Year ( date_of_calc ) - Year ( date_of_birth ) - ( date_of_calc < Date ( Month ( date_of_birth ) ; Day ( date_of_birth ) ; Year ( date_of_calc ) ) ) ) Calculation must be unstored for the benefit of people still alive.
October 16, 201312 yr Author Thanks again Mr. Comment; The calculation works great. Just need an additional feature which is to calculate the age in months and days if age is <1 year, years and months if age <6 years.
October 16, 201312 yr Ahmm... is this for medical purposes? If yes, I'd suggest calculating the month as equal to approximately 30 days and the year as equal to 365 days or so - rather than taking into account when exactly does the birthday fall in the current year/month. It makes the calculation simpler and more logical - otherwise you may find two people with exactly the same age in days having different ages when expressed in months and days.
October 16, 201312 yr Author Yes indeed, it is for medical purposes and I appreciate your suggestion. What if I have the same output format for all ages as follows : ##Y ##M ##D Is it logical ? If you agree, how can I do that? THANKS
October 16, 201312 yr Solution What if I have the same output format for all ages as follows : ##Y ##M ##D It makes very little difference: you can have one format for all = Let ( [ date_of_calc = Case ( date_of_death ; date_of_death ; Get ( CurrentDate ) ) ; n = date_of_calc- date_of_birth + 1; y = Div ( n ; 365.2425 ) ; r = Mod ( n ; 365.2425 ) ; m = Div ( r ; 30.436875 ) ; d = Round ( Mod ( r ; 30.436875 ) ; 0 ) ] ; y & "Y " & m & "M " & d & "D" ) or different formats for each group, as you asked before = Let ( [ date_of_calc = Case ( date_of_death ; date_of_death ; Get ( CurrentDate ) ) ; n = date_of_calc- date_of_birth + 1; y = Div ( n ; 365.2425 ) ; r = Mod ( n ; 365.2425 ) ; m = Div ( r ; 30.436875 ) ; d = Round ( Mod ( r ; 30.436875 ) ; 0 ) ] ; Case ( y < 1 ; m & "M " & d & "D" ; y < 6 ; y & "Y " & m & "M" ; y & "Y" ) ) The important part to remember is that that these are average months and years; so a patient may disagree with you when you state their age as 30, when their 30th birthday is still a few days away...
October 17, 201312 yr Author In fact, we encounter this age problem with patients every now and then; however, I can not be thankful enough for your great help.. These two formulas are great... THANXXXXXXXX
Create an account or sign in to comment