# Countdown til Sunrise/Sunset

Hi,

I’m wondering if anyone can help me with a countdown in hours and minutes until Sunrise/Sunset, IE a text display with; Sunset in X hours X minutes and then another one with Sunrise in X hours X minutes, I’ve already worked out how to make them transparent using `\$#DISDAYTIME#=true?100:0\$` for each text display bit, just not sure how to add the countdown.

Hope this makes sence.

1 Like

For how many hours are left:

``````(((#WRH#-#DH#)+24)-((floor(((#WRH#-#DH#)+24)/24))*24))
``````

For how many minutes are left:

``````(((#WRm#-#Dm#)+60)-((floor(((#WRm#-#Dm#)+60)/60))*60))
``````

#WRH# is for sunrise hour (0-23)
#WRm# is for sunrise minute
Change them for sunset tags to get the second set of numbers.

1 Like

Thank you so much this is perfect!!

1 Like

Thanks this helps me too

Question what the the “floor” element?

Floor basically rounds down to the lowest integer. So if you had floor(2.9), it would equal 2.

1 Like

I found there was a issue with this equation. It had to do with the hour variables being constant till the next hour.
example or problem:
Sunset is 18:34
Time is 17:35
Return of equation 1h59M
We need 0h59m

I scratched my head for a long time and solved this small issued, based on the work merllin did, but converting everything to minutes in the hour equation so we could get a hour with decimal. Then we floor the number.

Here is what I have.

Sunset
(floor((((#WSH#*60)+#WSm#)-((#DH#*60)+#Dm#))/60))h
(((#WSm#-#Dm#)+60)-((floor(((#WSm#-#Dm#)+60)/60))*60))m

Sunrise: (day of)
(floor((((#WRH#*60)+#WRm#)-((#DH#*60)+#Dm#))/60))h
(((#WRm#-#Dm#)+60)-((floor(((#WRm#-#Dm#)+60)/60))*60))m

Sunrise day before:
(floor(((((#WRH#*60)+#WRm#)+1440)-((#DH#*60)+#Dm#))/60))h
(((#WRm#-#Dm#)+60)-((floor(((#WRm#-#Dm#)+60)/60))*60))m