Maths function
MOD function in Google Sheets and Excel
MOD returns the remainder after dividing one number by another, with the same sign as the divisor.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
MOD(number, divisor)Arguments in [brackets] are optional. Google Sheets writes it MOD(dividend, divisor).
Example
=MOD(D2-C2,1) reads: Subtract the start time in C2 from the end time in D2, and keep only the part of a day that's left over, so an overnight shift isn't negative.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Date | Name | Start | End | Break | Duration |
| 2 | Mon 2 Mar | Mara | 9:00 | 17:30 | 30 min | 8:30 |
| 3 | Mon 2 Mar | Jonas | 8:15 | 16:45 | 45 min | 8:30 |
| 4 | Tue 3 Mar | Mara | 9:30 | 18:00 | 30 min | 8:30 |
| 5 | Tue 3 Mar | Priya | 22:00 | 6:00 | 30 min | 8:00 |
| 6 | Wed 4 Mar | Jonas | 7:45 | 15:15 | 30 min | 7:30 |
| 7 | Wed 4 Mar | Priya | 21:30 | 5:30 | 45 min | 8:00 |
| 8 | Thu 5 Mar | Mara | 10:00 | 19:15 | 60 min | 9:15 |
| 9 | Fri 6 Mar | Jonas | 8:00 | 12:30 | 0 min | 4:30 |
F2 shows 8:30 as before, and F5 now shows 8:00 for Priya's 22:00–06:00 shift, where plain subtraction would give −16 hours.
How the spreadsheet calculates it
Gives the remainder after dividing D2 minus C2 by 1.
- 1. MOD: Gives the remainder after dividing
D2minusC2by1.number=`D2-C2`: the value to wrapdivisor=`1`: `1`
More MOD examples
=MOD(10,3)1: ten divided by three leaves one.=MOD(D2-C2,1)*24A shift's length in decimal hours, overnight included.=IF(MOD(A2,2)=0,"Even","Odd")Whether the number in A2 is even or odd.=INT(B2/60)&"h "&MOD(B2,60)&"m"Minutes in B2 written as hours and minutes.
Paste any of these into the formula explainer to see it step by step.
Tips
- With times, divide by 1: the remainder is the time of day without whole days.
- Use
INTfor the whole part and MOD for the rest: 135 minutes isINT(135/60)hours andMOD(135,60)minutes. - Format time results as
h:mm, or multiply by 24 for decimal hours.
What MOD is used for
Shift lengths that cross midnight, splitting minutes into hours and minutes, even/odd checks, repeating patterns like every third row, and cycles such as rota days.
Arguments
| Argument | Required | What it is |
|---|---|---|
| number | Yes | The number to divide, or a calculation like D2-C2. |
| divisor | Yes | What to divide by. With times, 1 means one whole day.Watch out: A divisor of 0 gives #DIV/0!. |
Common mistakes
Wrapping only the start or the end: wrap the whole difference.
Expecting a negative result from a negative number:
MOD(-3,2)is 1, because the result takes the divisor's sign.Formatting an overnight-shift result as a number and seeing 0.33: time results need a time format like
h:mm.
In Google Sheets
Google Sheets has MOD(dividend, divisor): the same two arguments under different names, so the overnight-shift formula is written the same way in both apps.
Errors you may see with MOD
Questions
How do I calculate hours worked across midnight?
Wrap the difference: MOD(end-start,1). For 22:00 to 06:00 it gives 8:00, where plain subtraction gives a negative time.
How do I check if a number is even?
MOD(A2,2)=0 is TRUE for even numbers; MOD(A2,2)=1 for odd ones.
How do I highlight every other row?
Use MOD(ROW(),2)=0 as a conditional formatting rule: it's TRUE on every even row.
How do I turn minutes into hours and minutes?
Divide by 60 for the hours and keep the rest with MOD: for 135 minutes, INT(135/60) is 2 and MOD(135,60) is 15, so 2h 15m.
Sources
Official documentation the facts on this page were checked against.