Sensor: Length of daytime

Hello everyone,

I need a sensor that calculates the timespan between sun’s states next_rising and next_setting to measure length of daytime . I want the output to be in a specific format %H:%m (e.g. 08:23).

The calculation is simple: 86400 seconds of a day minus timespan between next_rising and next_setting but I don’t know how to format it into my desired format.

So far I have the value in seconds. How do i convert it to %H:%m?

{{ 86400 - (as_timestamp(states.sun.sun.attributes.next_rising) - as_timestamp(states.sun.sun.attributes.next_setting)) | int }}

Take a look here