keepcalculator

06 Numbers and Powers

Get nth Day of Week in Month: Formula & Calculator

Card No. 06·41227 · Updated · Standard formula, shown below

The calculator on this card is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

This calculator works out the date of the nth weekday in a month – for example, the second Monday of March or the last Friday of November. You enter the year, month, weekday, and which occurrence (1st, 2nd, 3rd, 4th, or last), and it returns the exact date. The calculation uses a simple formula based on the first day of the month and the weekday numbers, so you can also do it by hand with the steps below.

Formula

Let dow(1) be the day-of-week number (1=Monday … 7=Sunday) of the 1st day of the given month. The offset from the 1st to the first occurrence of the target weekday is:

offset = (targetWeekday – dow(1) + 7) % 7

Then the date of the n-th occurrence is:

date = 1 + offset + (n – 1) × 7

For the last occurrence (n=5 in the calculator), the date is the largest value of that expression that does not exceed the number of days in the month. In other words, if 1 + offset + 4×7 is greater than the month length, subtract 7.

Worked Example

Using the default values: year 2024, month 3 (March), weekday 1 (Monday), n=2 (second).

  • March 1, 2024 is a Friday, so dow(1) = 5.
  • offset = (1 – 5 + 7) % 7 = 3 % 7 = 3.
  • date = 1 + 3 + (2 – 1) × 7 = 1 + 3 + 7 = 11.

The second Monday of March 2024 is March 11, 2024 – which matches the calculator’s output.

How the Day-of-Week Numbering Works

In this system, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, and Sunday = 7. This is the ISO 8601 standard, widely used in Europe and in programming (Python’s isoweekday(), JavaScript’s getUTCDay() with adjustment). Some calendars start with Sunday as 0 or 1 – if you’re using a different convention, adjust the numbers accordingly. The formula still works, but the weekday numbers change.

To find the day-of-week of the 1st of a month by hand, you can use Zeller’s congruence or a known reference date. For example, January 1, 2000 was a Saturday (6). From there, count days forward, accounting for leap years. But the calculator does that automatically.

When to Use This Calculation

You’ll need this when scheduling recurring events that fall on a specific weekday occurrence:

  • Payroll dates (e.g., the last Friday of the month)
  • Board meetings (e.g., the second Tuesday)
  • Community events (e.g., the first Saturday)
  • Holidays like Thanksgiving (fourth Thursday in November, US) or Mother’s Day (second Sunday in May, many countries)
  • Billing cycles, subscription renewals, and recurring reminders

It’s also useful for generating calendar widgets or scheduling scripts where you need to compute dates programmatically.

Common Mistakes and Misconceptions

One frequent error is mixing up weekday numbering – if you use Sunday=1 instead of Monday=1, your offset will be off by one. Another is forgetting that “the last weekday� is not always the 5th occurrence; if the month has fewer than 5 of that weekday, the 5th is actually the next month’s first. The calculator handles this by using n=5 as “last.�

Also, be careful with leap years – February has 29 days in leap years, which can shift the last occurrence. For example, in February 2024 (leap year), the last Monday is the 26th, not the 19th as in a non-leap year.

Alternative Methods

If you don’t have this calculator, you can use spreadsheet formulas. In Excel or Google Sheets, the date of the nth weekday is:

=DATE(year, month, 1) + (weekday_num - WEEKDAY(DATE(year, month, 1), 2)) + (n-1)*7

where weekday_num is 1=Monday … 7=Sunday and the return type 2 in WEEKDAY gives Monday=1. For the last occurrence, use =DATE(year, month+1, 1) - WEEKDAY(DATE(year, month+1, 1), 2) - (7 - weekday_num) or simply take the 5th occurrence and check if it’s still in the month.

Programming languages also have built-in functions, like Python’s calendar.monthcalendar() or JavaScript’s Date object with a loop.

Limitations of the Formula

The formula assumes the Gregorian calendar, which is the standard in most of the world. It works for any year from 1900 to 2100 (the calculator’s range). If you need dates outside that range, the underlying math still holds, but the calculator won’t accept them. Also, the formula returns the date as a number in YYYYMMDD format – you can mentally convert to a readable date, or use the calculator’s output as-is.

Note that the calculator uses the “last� option for n=5, not a true fifth occurrence. If you specifically want the fifth occurrence and it doesn’t exist, the calculator will return a date in the next month – but that’s not what you want. Use n=5 only when you mean “last.�

Frequently Asked Questions

What if I want the 5th Monday, but that month only has 4 Mondays?

If you ask for the 5th occurrence and it doesn’t exist, the calculator’s “last� mode (n=5) returns the 4th (the last) Monday. If you truly need the 5th, you’ll have to check if the 5th is still in the same month – if not, it falls in the next month. For example, the 5th Monday of March 2024 would be April 1, 2024, because March has 5 Mondays in 2024 (March 4, 11, 18, 25, and April 1 is not in March).

How do I find the day of the week for the 1st of a month without a calculator?

You can use Zeller’s congruence, or memorize a reference date. For instance, January 1, 2000 was a Saturday. From there, count days, accounting for leap years (every 4 years, except century years not divisible by 400). Or use the Doomsday algorithm, which gives the day of the week for any date using anchor days.

Why does the formula use (targetWeekday – dow(1) + 7) % 7?

The modulo operation ensures the offset is between 0 and 6. If the target weekday is earlier in the week than the 1st, the +7 keeps the result positive. For example, if the 1st is a Wednesday (3) and you want Monday (1), the difference is -2, +7 gives 5, and %7 gives 5 – meaning the first Monday is 5 days after the 1st.

Does this work for any year, like 1800 or 2500?

The Gregorian calendar was adopted in 1582, but different countries switched at different times. For most applications, the formula works for any year after 1582, but the calculator restricts to 1900–2100 for practicality. If you need earlier dates, you can use the formula manually – just be aware of calendar transitions (e.g., the UK switched in 1752, losing 11 days).

What’s the difference between “nth� and “last� in the calculator?

“nth� means the exact occurrence number (1st, 2nd, 3rd, 4th). “Last� (n=5) means the final occurrence of that weekday in the month, which could be the 4th or 5th depending on the month’s length and start day. For example, the last Monday of February 2024 is the 26th (the 4th Monday), while the last Monday of March 2024 is the 25th (the 5th Monday).

Can I use this to find the date of Thanksgiving or other holidays?

Yes. Thanksgiving in the US is the fourth Thursday of November, so set year, month=11, weekday=4 (Thursday), n=4. Mother’s Day in many countries is the second Sunday of May – set weekday=7, n=2. Just be aware that some holidays use different rules (e.g., Easter is based on the lunar calendar).

Related

Formula used
in year | Year | - | 2024 | 1900 | 2100
in month | Month | - | 3 | 1 | 12
in weekday | Weekday (1=Mon...7=Sun) | - | 1 | 1 | 7
in n | nth (1-4, or 5=last) | - | 2 | 1 | 5
out date | Date | - | (year * 10000 + month * 100 + 1 + ((weekday - dow(1) + 7) % 7) + (n - 1) * 7 + (n == 5 ? max(0, days - 1 - ((weekday - dow(1) + 7) % 7) - ((n - 1) * 7)) : 0)) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →