Calculating age of persons with GREL diff()

i want to calculate the age of persons using the GREL diff().

the following example return 79 for a person born on 20 January 1945, calculating its age on 20 April 2025; which should be 80:

diff("2025-04-20".toDate("YYYY-MM-DD"),"1945-01-20".toDate("YYYY-MM-DD"),"years")

Hi @LibrErli, it looks like this is a side effect of using the Java SimpleDateFormat syntax for the format string of toDate. When I run "2025-04-20".toDate("YYYY-MM-DD"), I get back [date 2024-12-29T00:00:00Z], which is not what I would have expected. Instead, can you try using yyyy-M-d as your date string for both dates? I get the expected date when I use that format string, and therefore the right diff output.

1 Like

Hi @Rory thanks a lot for your explanation. This helps a lot. Do we need some clarification in the documentation of the GREL-functions for date types? or should i make an issue on github?

Hi @LibrErli where do you think it needs improved docs? I ask because we recently made sure our date functions and string functions were explained well and updated a few areas, but certainly could use your viewpoints. You are welcome to make a PR at any time.

1 Like

hi @thadguidry i am absolutely sorry, now i have read the docs about date functions one more again, even exactly and it contains all the necessary information i wasn't able to understand before posting my question. shame on me! :pensive_face:

1 Like