I'm not sure about this military time stuff - is it possible to format Excel cell containing date or time as military time (format "hhmm"), or it is really an integer value, but anyway having only time registered (without date part) will make any calculations with those times (on and off) a headache!
Let's assume you have columns OnTime and OffTime formatted as time (I'll leave military part off now - so "hh:mm" - i.e. without date part).
When both OnTime and OffTime are always on same date, calculating working time is easy:
WorkTime = OffTime - OnTime. Like 16:00 - 08:00 = 08:00.
When OnTime is on one date, and OffTime is on next date, and working time is less than 24 hours (like OnTime = 16:00 and OffTime = 02:00), the formula for WorkTime must check which time has greater value. When OffTime is greater, then WorkTime = OnTime - OffTime. When OnTime is greater, then WorkTime = 24:00 - OnTime + OffTime.
Thins get more messy, when working time can be more than 24 hours. Like OnTime = 16:00 on first day, and OffTime = 18:00 on next day. Having only time registered, you have no way to check, were you off on same day or on next one.
The only way to make the calculation foolproof, is to include date part too (NB! You can format both columns to display only time, but you have to enter date and time!). Like
OnTime = 26.07.2022 16:00, OffTime = 27.07.2022 18:00. Column WorkTime must be formatted as "[h]:mm" (NB! Brackets are essential here!). The formula for WorkTime will be simply WorkTime = OffTime - OnTime, and will return 26:00 (This format displays times over 24 hours. Any other time format displays 02:00!).
When you can format datetime columns as military time, the last formula will work too. When you can't - then maybe someone can give better advice!
|