Sunset minus Sunrise equals ONE hour?!?


#1

1) Give a description of the problem
I have a piston where I calculate ($sunset-$sunrise) to find the length of day.
It has been working for months, but recently, it started returning 1 hour

2) What is the expected behavior?
It should be 13 hours

3) What is happening/not happening?
Try this in the console to see what I mean:
formatDateTime(time($sunset-$sunrise), "h:mm")

temp

It is like webCoRE is ignoring the extra 12 hours for the afternoon time.
temp
Do I need something like $sunset24 to get the correct response,
or do I need to cheat and add 12 hours during half of the year?


#2

Try this.

formatDateTime(time($midnight -$sunset) +time($sunrise-$midnight ),”hh:mm")


#3

Oops. Rearrange them and adjust. That is for sunset to sunrise. But you get the idea


#4

Thanks for the response, but neither works:

temp


#5

What about using formatDuration() instead?

formatDuration($sunset - $sunrise)


#6

formatDuration works but when I try to make the results display the way I want, it returns incorrect data again.

(expression) formatDuration($sunset - $sunrise) »»» (string) 13:12:00
(expression) formatDateTime(formatDuration($sunset - $sunrise), “h:mm”) »»» (string) 1:12

What am I missing?


#7

I guess the real question is, why does the command:

formatDateTime("13:12:00", "h:mm")
return:
1:12

No matter how many hours I put in, the answer is always 12 or less

temp


#8

Use a capital “H” to return 24-hour format


#9

Brilliant! That was it!! Thanks @allrak

(I didn’t need that until the days got long, but your method should work all year)