Calculate the Date of Thanksgiving (USA and Canada)
You need to calculate when Thanksgiving is in a given year.
The following functions return the day of Thanksgiving for a given year. If no year is given then current year is used.
In the USA Thanksgiving is celebrated on the fourth Thursday in November:
In Canada it is the second Monday in October:
The idea is very simple:
- Find out what day of the week is the first day of respective month (November for USA, October for Canada).
- Calculate offset from that day to the next occurrence of weekday required (Thursday for USA, Monday for Canada).
- Add that offset to the first possible date of the holiday (22nd for USA Thanksgiving, 8th for Canada).