Age of person in years, months, days, hours, minutes, seconds

Hi All,
I have tried but have not found any elegant way to create a template sensor to show me the age of my newborn. The format would display the age in the format: years, months, days, hours, minutes, seconds.

If anybody can help with an example, that would be much appreciated.

That’s because our calendar, with its irregular length months, makes a relative calculation like that stupidly complicated to do in Jinja… There is a python module relativedelta that does those types of calculations, but (as far as I know) you can’t access it through templates in HA.

If it’s a newborn then age in days can be done like this:

{% set birth_date = '2021-12-25 14:25:30' | as_datetime | as_local %}
{{ (now() - birth_date).days }}

otherwise, what digderidrew said (date calculations over long periods of time can be fiendishly complicated).

Yeah, getting days is straightforward… I have the sensor showing weeks and days rather than days, but as our baby is getting older… I would need for the sensor to show 1 year 2 months 3 days 4 hours 53 sec :slightly_frowning_face:

@Didgeridrew So the only way, for now, is to do the integration for it isn’t it? Too bad I do not have experience with building integrations :cry:

You could use a scrape sensor and let someone else do the dirty job.

This however removes seconds, minutes and hours of the output.

https://www.calculator.net/age-calculator.html?today=01%2F25%2F2021&ageat=01%2F31%2F2022&x=109&y=23

And as you can see from the link you can probably feed the link with the dates you need to compare

Unlike the old days when the color of the life-clock crystal in the palm of one’s left hand indicated your age (and when it was time to “renew”).

2 Likes