Time Difference Between 5AM to current Time

I am trying to figure out how to make this code work. I see many examples that show how to get the difference between dates but not any for time difference. I would appreciate any help!

system.date.getMinutes() doesn't accept a string as input.
All of the system.date functions either accept or return Java's Date class, which represents a date + time as milliseconds since "epoch" (Jan 1, 1970, at midnight UTC).

If you want to get the delta between "right now" and "today at 5 AM", you need to get a datetime that represents "today at 5 AM".
The way to do that is system.date.setTime, as in:

first = system.date.setTime(system.date.now(), 5, 0, 0)
second = system.date.now()

print system.date.minutesBetween(first, second)
2 Likes

if I can put in my plug to use java.util.Calendar I find it really elegantly handles datetime differences and setting things like 5 am today. But you will end up working in milliseconds instead of cleanly in minutes.