Main UI: Show timedelta now()-datetime filed?

I would like to show the timedelta between now() and the value of a datetime field. Do I need to create a seperate item for it and a rule that regularly updates this field? Or is it possible to dynamically compute the timedelta in the UI itself with an expression?
Any hint is appreciated.

Dominik

There is a minimal date/time library available in the UI widgets: dayjs. This can easily display a human friendly difference between a timestamp and now:

dayjs(items["YourItemName"].state).fromNow()

You can use this anywhere in the UI widgets where you can set expressions and you’ll get results like this:
image

5 Likes

Thanks! This is exactly what I was looking for.