#Days in the year

1 messages · Page 1 of 1 (latest)

slender shoal
#

Hi, I'm wracking my brain trying to figure out how to get the number of days in a UTC year.

This sensor works fine if I'm querying the year in local time:
- name: DaysInTheYear state: "{{strptime('12/31/'+((states('sensor.date')|as_datetime).year|string), '%m/%d/%Y').timetuple().tm_yday|int}}"

But I want to query the year in UTC. I know this is a niche case, only affecting me for 6 hours each December 31 , but it would be nice to have.

Can anyone please help? Thanks in advance!

ruby zephyr
#

Not sure I fully understand what you want to achieve and why you're ignoring time when it's about timezones but this should do it:

{{ utcnow().replace(day=31, month=12).timetuple().tm_yday | int }}
#

For local time you can use now() instead of utcnow()

slender shoal