Thanksgiving Day calculator
By , journalist and programmer
In many countries Thanksgiving Day ("for harvest and labour", as the Dutch say) is a religious matter. It is only celebrated inside the churches and non-christians very often don't even know the date of the event. In North-America this is quite different. Thanksgiving is a yearly public holiday in the USA as well in Canada.
In the United States of America Thanksgiving Day is celebrated on the fourth Thursday in November. So, the first occurrence will be on:

The Canadians have their Thanksgiving festivities on the second Monday in October. Next Thanksgiving in Canada is:

The engine
The engine of this code (for PBWin) is based upon a trick that converts calendar dates to an integer number, either a so called Julian Day Number, as used in my week number calculator or a value that can be derived from Windows' native way to keep track of elapsed time since January 1, 1601 (00:00:00 UTC). For the Thanksgiving Day calculator code the latter is used.

Windows keeps track of time in portions of 100 nanoseconds, stored in a structure called FILETIME. Once you know the filetime for a certain calendar date, simply divide this by 24 times 60 times 60 times 10,000,000, i.e. the number of 100-nanoseconds-portions for a full day. This gives 0 for "01/01/1601", 1 for "01/02/1601" etcetera.

Here's the sequence of calculations to find, for instance, the 4th Thursday of November:
   find 'daynumber' for the day prior to November 1
   increase this value until a Thursday is found - this is the first Thursday of the month
   the 4th Thursday is 3 weeks later, so add (4 - 1) times 7 days
   finally, convert the resulting 'daynumber' to a calendar date


Where to download?
   Click here to download the source code.
   Back to homepage

Copyright © 2002: Egbert Zijlema
Failed to execute script '/cgi-bin/hidden.exe?thanks': Win32 Error Code = 2