Finding the Nth Occurrence of a Weekday in a Month
Summary
This document explains a calendar function for finding a specified occurrence of a weekday within a month, such as the third Monday in January or the last Thursday in December. Its inputs are a year, month, weekday number, and occurrence number. Weekdays are numbered Monday through Sunday, and the occurrence can be from the first to the fifth.
If the requested fifth occurrence does not exist in that month, the function returns the fourth occurrence instead. The examples show how to request a second Friday and a fifth Thursday, the latter used to find the last Thursday of a month. This can help schedule indicators or trading logic around calendar events defined by weekday position. The document describes the function’s behavior and gives usage examples, but provides no performance evidence or discussion of calendar edge cases beyond the missing-fifth-day fallback.
Key ideas
- The function identifies a weekday by its position within a specified month.
- Inputs include year, month, weekday number, and occurrence number.
- Weekdays are numbered from Monday as one through Sunday as seven.
- When a requested fifth weekday does not occur, the function returns the fourth occurrence.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.