Skip to main content
Solved

Calculate an age with a birth day


philippeb
Enthusiast
Forum|alt.badge.img+20

Hi,

I have birth days in this format YYYY-MM-DD.

I want to calculate their ages.

Per exemple, someone born 1950-03-28 would be 70 years old.

Not sure how to do that. Any idea?

Thanks

Best answer by ebygomm

I'd probably use the Date/Time Functions, so parse the attribute named birthdate into date format, calculate the difference in years from today's date and round down

@floor(@DateTimeDiff(@DateTimeNow(),@DateTimeParse(@Value(birthdate),%Y-%m-%d),Years))

0684Q00000ArKSRQA3.png

View original
Did this help you find an answer to your question?

4 replies

david_r
Celebrity
  • June 9, 2020

Convert both dates to seconds since epoch (%Es), find the difference, then convert back to years. If you don't need to take leap years into account, the easiest is to divide by 31556952 (the number of seconds in a non-leap year).


david_r
Celebrity
  • June 9, 2020

Or to be completely accurate (using leap years and all), first convert the dates to FME timestamps then use the DateTimeCalculator:


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • Best Answer
  • June 9, 2020

I'd probably use the Date/Time Functions, so parse the attribute named birthdate into date format, calculate the difference in years from today's date and round down

@floor(@DateTimeDiff(@DateTimeNow(),@DateTimeParse(@Value(birthdate),%Y-%m-%d),Years))

0684Q00000ArKSRQA3.png


philippeb
Enthusiast
Forum|alt.badge.img+20
  • Author
  • Enthusiast
  • June 9, 2020
david_r wrote:

Or to be completely accurate (using leap years and all), first convert the dates to FME timestamps then use the DateTimeCalculator:

Nice I didn't know we could do that :D

I need to put an AttributeRounder after to take out de decimals though.

Thanks!!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings