Possible to calculate age from a value in .md file?

I am working on a site for a law firm who are requesting that the age of their team members be visible on the site. They are okay with the ages only updating on every new deployment, and do not want the entire birth year to be available statically on the front end (just the calculated output)

This is what my markdown file contains as their birthdate:
birthDate: 1992-04-24

What would you suggest I do?

1 Like

Note that there may be a potential time zone issue for when the person has birthday, but I guess since you do this “every new deployment”, something like this should be good enough:

{{ $diff := now.Sub .Params.birthDate }}
{{ $years := div (div $diff.Hours 24) 365 }}

I just wrote the above directly in here, so … there may be errors.

2 Likes

You’re a genius. I’ve modified the code for a solution that worked for me below.

{{ $diff := now.Sub (time .Params.birthDate) }}
{{ $years := div (div $diff.Hours 24) 365 }}
{{ math.Floor $years }}

Thanks man, you’re a savior :slight_smile:

2 Likes