In the office, a special machine record the time when you start working (clock in office) and when you finish working (clock out of office). We can calculate the total working time by subtracting the end working time from the start working time.
If we also take out the lunch break, we have to subtract the lunch break from the total working time we get. See example below, we calculate effective working hours with the help of Excel MOD function, launch break is “thrown away”.
Before creating the formula to calculate the working time, we should first set the number format to “Time”.
In this example, the formula is:
Here, you may wonder why we use the MOD function instead of just using the simple addition and subtraction operations. Firstly, let’s introduce Excel MOD function.
MOD function lists in Excel Formulas->Math & Trig functions.
MOD function returns the remainder of two numbers in a division operation.
=MOD (number, divisor)
For example, MOD(5,3)=2.
In the first MOD function:
Subtract the start working time from the end working time, then we can get “total working hours”.
In the second MOD function:
Subtract the start of the lunch break from the end of the lunch break to get “lunch break time”.
In this example, on Friday, the start time is Thursday 6:30:00 PM, but the end time is Friday 6:00:00 PM (cross midnight). If we ignore the day of the week, then the start time is later than the end time, and without the MOD function, Excel would return an error if it applied only subtraction operations. To cover the “across midnight” case (start time later than the end time, but lasting no more than 24 hours), we set the divisor argument to “1” to avoid getting a negative value. That’s why we apply Excel MOD function here to calculate working hours.
Take Friday as an example to calculate the working hours.
Total 21 hours and 30 minutes are displayed after running the formula.
If we just apply subtraction, the number cannot be shown in “Time” format properly.
If we set number format to “General”, a negative number is displayed.
In the example, the formula =MOD(C3-B3,1)-MOD(E3-D3,1) is equivalent to “total working hours” minus “lunch break”. So the actual working time is calculated correctly by this formula.
- Excel MOD function
the Excel MOD function returns the remainder of two numbers after division. So you can use the MOD function to get the remainder after a number is divided by a divisor in Excel. The syntax of the MOD function is as below:=MOD (number, divisor)….