add hours... - Forum

Forum Navigation
You need to log in to create posts and topics.

add hours...

Hello,

Is it possible to add an hour to an hour ( ie: 12h35 + 08:24) ?

Regards,

@cdy44-2

This is Part I (gives you [endHour] and [endMinute] as integers) ...

SetVar [startTimeString] "12h35"
... separate hour and minute
StrParse "[startTimeString]" "h" [startTime]

SetVar [addTimeString] "08:24"
... separate hour and minute
StrParse "[addTimeString]" ":" [addTime]

... convert to absolute minutes
Math "([startTime(0)]*60) + [startTime(1)]" "0" "[startMinutes]"
Math "([addTime(0)]*60) + [addTime(1)]" "0" "[addMinutes]"

... add the absolute minutes
Math "[startMinutes] + [addMinutes]" "0" "[endMinutes]"

... convert back to hour and minute
Math "[endMinutes]/60" "5" "[endHourDecimal]"
MathFloor [endHourDecimal] [endHour]
Math "[endMinutes] - ([endHour]*60)" "0" "[endMinute]"

... show result
AlertBox "Result Time" "[endHour] [endMinute]" ""

... I am not sure ...

a) if you need to show the result as am/pm or 24 hour time (i.e. 15h45 or 3:45 pm etc.)

b) what you want to do when the end time rolls into next day (i.e. [endHour] [endMinute] goes over 23 59)

c) if time to be added can go over 24 hours (e.g. "32:15")

... once you answer these questions, I can assist in converting [endHour] [endMinute] to desired result.

Hello Gaev,

Thank you very much for your clear answer. I will try it as soon as I have time to do.
Have a nice day !
Best regards,