Time between e.g 22:00PM and 08:00AM

Hello,

How can I calculate the time between two clock times that cross midnight?

I don’t want to use a date picker as the date is irrelevant. The user should only input the start and end time, for example 10:00 PM - 08:00 AM. I want to calculate how many hours this is, which would be 10 hours. Subtracting the end time from the start time won’t work in this scenario.

Let them input whatever time, and then to calculate you will need to use the current date time to do the calculation.

Start: current date time: change hours to X1 change minutes to Y1
End: current date time: change hours to X2 change minutes to Y2

End - Start = time between (if negative, then multiply the number by -1)

This depends on how you are providing the user with the choices…if it is from a dropdown that uses an option set you create with hours of the day, then simply add an attribute to the option values to be ‘total number of minutes’ and subtract the two and if the end is less than the start do a *-1

But, sounds like you intend to use a date-time picker, which will also be choosing a date, so simply take the end date/time minus the start date time and use operator :format as number of hours

This topic was automatically closed after 70 days. New replies are no longer allowed.