# Ordinal date

Jump to navigation Jump to search

An ordinal date is a calendar date typically consisting of a year and a day of year ranging between 1 and 366 (starting on January 1), though year may sometimes be omitted. The two numbers can be formatted as YYYY-DDD to comply with the ISO 8601 ordinal date format.

## Calculation

Computation of the ordinal date within a year is part of calculating the ordinal date throughout the years from a reference date, such as the Julian date. It is also part of calculating the day of the week, though for this purpose modulo-7 simplifications can be made.

For these purposes it is convenient to count January and February as month 13 and 14 of the previous year, for two reasons: the shortness of February and its variable length. In that case the date counted from 1 March is given by

floor ( 30.6 ( m + 1 ) ) + d − 122

which can also be written

floor (30.6 m − 91.4 ) + d

with m the month number and d the date.

The formula reflects the fact that any five consecutive months in the range March–January have a total length of 153 days, due to a fixed pattern 31–30–31–30–31 repeating itself twice.

"Doomsday" properties:

For m = 2n and d=m we get

floor (63.2 n − 91.4 )

giving consecutive differences of 63 (9 weeks) for n = 2, 3, 4, 5, and 6, i.e., between 4/4, 6/6, 8/8, 10/10, and 12/12.

For m = 2n + 1 and d=m + 4 we get

floor (63.2 n − 56.8 )

and with m and d interchanged

floor (63.2 n − 56.8 + 118.4 )

giving a difference of 119 (17 weeks) for n = 2 (difference between 5/9 and 9/5), and also for n = 3 (difference between 7/11 and 11/7).

The ordinal date from 1 January is:

• for January: d
• for February: d + 31
• for the other months: the ordinal date from 1 March plus 59, or 60 in a leap year

or equivalently, the ordinal date from 1 March of the previous year (for which the formula above can be used) minus 306.

### Modulo 7

Again counting January and February as month 13 and 14 of the previous year, the date counted from 1 March is modulo 7 equal to

floor (2.6 m − 0.4 ) + d

with m the month number and d the date.

Calculation can be done starting with January 1 mathematically without if statements if we take advantage of min and max algebraic logic
MAX is 1/2*(a+b+|a-b|)
MIN is 1/2*(a+b-|a-b|)

provided the month(m) day(d) and year(y)
(MAX(0,MIN(1,m-1))*31)+ //if Jan is a full month
(MAX(0,MIN(1,m-2))*28)+ //if Feb is a full month
(MAX(0,MIN(1,m-3))*31)+ //if Mar is a full month
(MAX(0,MIN(1,m-4))*30)+ //if Apr is a full month
(MAX(0,MIN(1,m-5))*31)+ //if May is a full month
(MAX(0,MIN(1,m-6))*30)+ //if June is a full month
(MAX(0,MIN(1,m-7))*31)+ //if July is a full month
(MAX(0,MIN(1,m-8))*31)+ //if Aug is a full month
(MAX(0,MIN(1,m-9))*30)+ //if Sept is a full month
(MAX(0,MIN(1,m-10))*31)+ //if Oct is a full month
(MAX(0,MIN(1,m-11))*30)+ //if Nov is a full month
d+ //days of current month
(((INT((y)/4)-INT((y)/100)+INT((y)/400)) //leap year logic
-(INT((y-1)/4)-INT((y-1)/100)+INT((y-1)/400)))*MAX(0,MIN(1,m-2))) //only count a leap year if date is >=3rd month //leap year logic

example of Aug 24th 2016 is 31+28+31+30+31+30+31+0+0+0+0+24+1

## Table

 To the day of i Add Leap years Algorithm 13Jan 14Feb 3Mar 4Apr 5May 6Jun 7Jul 8Aug 9Sep 10Oct 11Nov 12Dec 0 31 59 90 120 151 181 212 243 273 304 334 3 0 31 60 91 121 152 182 213 244 274 305 335 2 30 (m - 1) + floor (0.6 (m + 1)) - i

For example, the ordinal date of April 15 is 90 + 15 = 105 in a common year, and 91 + 15 = 106 in a leap year.

## Month–day

The number of the month and date is given by

m = floor (od/30) + 1
d = mod (od, 30) + i - floor (0.6 (m + 1))

the term mod (od, 30) can also be replaced by od - 30 (m - 1) with od the ordinal date.

• Day 100 of a common year:
m = floor (100/30) + 1 = 4
d = mod (100, 30) + 3 - floor (0.6 (4 + 1)) = 10 + 3 - 3 = 10
April 10.
• Day 200 of a common year:
m = floor (200/30) + 1 = 7
d = mod (200, 30) + 3 - floor (0.6 (7 + 1)) = 20 + 3 - 4 = 19
July 19.
• Day 300 of a leap year:
m = floor (300/30) + 1 = 11
d = mod (300, 30) + 2 - floor (0.6 (11 + 1)) = 0 + 2 - 7 = -5
November -5 = October 26 (31 - 5).