How do I find # of minutes between $sunset and 10:00 PM?


#1

I’ve got a piston I’m working on that requires me to have an expression that will tell me how many minutes there are between $sunset and 10:00 PM.

I’ve tried 10,000 different ways and I can’t seem to come up with the answer. I know what the answer should be, but there’s no way I can make an expression come up with it.

Any help out there?


#2

How about:

(time('10:00:00 PM CST')-time($sunset))/1000/60

Obviously, use your timezone in there…


#3

set variable (intMinutes) = ((addhours($nextMidnight, -2) - $sunset) / 60000);


#4

Oh, I like that. Gets around the date complication nicely.


#5

Thanks. I helped someone make a piston where they wanted to turn on a light at a random time between sunset and 11PM. Took a few iterations, but that’s what eventually worked out very well.

Once you have that number…you can then do something like:

wait randomly between 0 and intMinutes minutes
Turn on light
wait randomly between 10 and 20 minutes
turn off light


#6

This works perfectly! Thanks so much. Very elegant solution.


#7

this one works with time only:

(time(‘22:00’) - time($sunset)) / 60000