Cover V03, I03
Article
Listing 1
Sidebar 1
Table 1
Table 2

may94.tar


Table 1: Days of the year

Jan: 0 Apr: 90 Jul: 181 Oct: 273
Feb: 31 May: 120 Aug: 212 Nov: 304
Mar: 59 Jun: 151 Sep: 243 Dec: 334

If the year is a leap year, add one to every month after February.

To find the day number of the year for a particular date, add the number for the month from the table above to the day of the month. Two easy examples are Jan 1 (0 + 1 = 1) and Dec 31 (334 + 31 = 365). Apr 12 is 102 (90 + 12) and Oct 30 is 303 (273 + 30). If you need a zero-based day number, such as that commonly used in the TZ environment variable's start and end dates, subtract one from the result.

If you ever need to convert back from a day number to a date, find the largest month number smaller than the day number you're converting and subtract it. So, 116 is Apr 26 because May (120) is larger than 116, so subtract April's number (90) from 116 leaving 26. If the original number is zero-based, add one to it before subtracting, so 116 is really 117, thus Apr 27.