Specific date/time code - calculation

I have a date and time code, that looks like this:

I would like to know the minutes from {{ now().strftime("%Y%m%d%H%M") }}.

What would be the best/easiest way to do that?

The minutes portion of that datetime, total minutes for the day, epoch, or what?

Also: The EPIC Time Conversion and Manipulation Thread!.

And did you read the templating docs?

Use python’s inherent ability to slice strings. This slices the last two characters of the supplied string:

{{ states('sensor.your_sensor)[-2:] }}

On the other hand, if all you want is the minutes of the current time, then it’s simply this:

{{ now().minute }}

I want the absolute difference in minutes. They are in the same time zone.

You’re not providing enough information in your posts and we’re left with guessing what you want.

For example, your latest post introduces a requirement that wasn’t mentioned in your first post. You now want the “absolute difference in minutes”. The difference between what two things?

Maybe lost in translation but I wanted to have the difference between 202203251159 and now().strftime("%Y%m%d%H%M").

Sorry, if this wasn‘t clear.

The difference between the future date and today is 19848 minutes.

{{ ((strptime('202203251159', '%Y%m%d%H%M') | as_local - now()).total_seconds() / 60) | round(0)  }}

1 Like