October 2nd, 2008 Posted in Formulas and Functions | 1 Comment »
It’s daylight saving time again. Clocks go forward on the last Sunday in September and get put back on the first Sunday in March.
Perhaps you, like me, need an Excel formula that calculates the first and last Sunday in a month. In this post I’ll discuss a relatively simple formula that does that for you. The formula can be extended quite easily to cover other days of the week too.
I’ll start with a formula for calculating the date of the first Sunday in a month. The formula I’ve come up with relies on three Excel functions: Date, Weekday and Mod. The basic approach is to use the Date function to find the first day of the month. By applying the Weekday function to this date we can work out whether the first day of the month is a Sunday, Monday, Tuesday etc. Armed with this information we can calculate how many days we need to add to the first day of the month in order to arrive at the date of the first Sunday in the month.
In this post I’ll assume that the month (1 for January, 2 for February etc) is entered in cell A1 and the year (2015 for example) is entered in cell A2. Based on this, the Excel formula for calculating the first Sunday is:
= DATE(A2, A1, 1) + MOD(1 - WEEKDAY(DATE(A2, A1, 1)), 7)
Here’s a screenshot of the formula in action:

The screenshot shows the formula in an expanded format along with the intermediate results of the calculation. In this case we’re calculating the date of the first Sunday in September 2015.
But what if you want to find the first Monday of the month? That’s easy. Just change the 1 that follows “MOD(“ to 2. This gives us:
= DATE(A2, A1, 1) + MOD(2 - WEEKDAY(DATE(A2, A1, 1)), 7)
With a minor adjustment the formula can be used for the other days of the week too. Just replace the “1” with 3 for Tuesday, 4 for Wednesday, 5 for Thursday, 6 for Friday and 7 for Saturday.
Now that we’ve looked at calculating the first Sunday in a month, let’s turn our attention to the last Sunday in a month. We need only make a couple of small changes to the first formula to get a workable formula. Here’s the formula I’ve come up with:
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 1, 7)
I’ve rearranged a couple of items in the first formula, used 0 instead of 1 in the Excel Date function and increased the month by 1. The Date function calculates the day before the 1st day of month A1+1 – that is, the last day of month A1. Given this we can calculate how many days we need to subtract in order to arrive at the last Sunday of the month. To make things clearer, here’s how you would use the formula to find the last Sunday in September 2010:
= DATE(2010, 9 + 1, 0) - MOD(WEEKDAY(DATE(2010, 9 + 1, 0)) - 1, 7)
It’s easy to amend this formula if you want to find the last day of the month for other days of the week. Just replace the 1 which precedes “, 7)” with 2 for Monday, 3 for Tuesday, 4 for Wednesday, 5 for Thursday, 6 for Friday and 7 for Saturday. So, for example, the last Thursday in a month would be:
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 5, 7)
These formulas can be extended still further. As an example, suppose you want to find the second Sunday in a month. This is easy to do - just add 7 to the result returned by the formula at the top of this page. If you want the third Sunday in a month, just add 14 instead of 7. Similarly, given the last Sunday in a month, subtract 7 and you’ll get the second last Sunday in a month.
For convenience I’ve summarized most of these formulas in the tables below:
First Day Formula
| Day |
Formula for First Day in Month |
| Sunday |
= DATE(A2, A1, 1) + MOD(1 - WEEKDAY(DATE(A2, A1, 1)), 7) |
| Monday |
= DATE(A2, A1, 1) + MOD(2 - WEEKDAY(DATE(A2, A1, 1)), 7) |
| Tuesday |
= DATE(A2, A1, 1) + MOD(3 - WEEKDAY(DATE(A2, A1, 1)), 7) |
| Wednesday |
= DATE(A2, A1, 1) + MOD(4 - WEEKDAY(DATE(A2, A1, 1)), 7) |
| Thursday |
= DATE(A2, A1, 1) + MOD(5 - WEEKDAY(DATE(A2, A1, 1)), 7) |
| Friday |
= DATE(A2, A1, 1) + MOD(6 - WEEKDAY(DATE(A2, A1, 1)), 7) |
| Saturday |
= DATE(A2, A1, 1) + MOD(7 - WEEKDAY(DATE(A2, A1, 1)), 7) |
Last Day Formula
| Day |
Formula for Last Day in Month |
| Sunday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 1, 7) |
| Monday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 2, 7) |
| Tuesday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 3, 7) |
| Wednesday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 4, 7) |
| Thursday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 5, 7) |
| Friday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 6, 7) |
| Saturday |
= DATE(A2, A1 + 1, 0) - MOD(WEEKDAY(DATE(A2, A1 + 1, 0)) - 7, 7) |
Tags: date function, excel formula, excel function, weekday function