This site is supported by donations to The OEIS Foundation.

Template:To day of CE

From OeisWiki
Jump to: navigation, search

The {{To day of CE}} date and time template returns the day of CE (Christ Era) for a given year, month and day of month.

Usage

{{To day of CE|year=year as a nonzero unformatted integer in [1..10000]|month=month as two digit number in [1..12], abbreviation or full name|monthday=day of month}}

or

{{To day of CE|year as a nonzero unformatted integer in [1..10000]|month as two digit number in [1..12], abbreviation or full name|day of month}}

or

{{To day of CE}} where year, month and monthday default to local year, local month and local day of month for OEIS Wiki server

Examples

With MySQL, the Days Since 1 A.D. functions give[1]


TO_DAYS(date) returns the number of days since the first day in the year 1 A.D. (there was no year 0).

The opposite effect is obtained by using FROM_DAYS(number).

mysql>
mysql> select TO_DAYS('2000-01-01') ;
+-----------------------+
| TO_DAYS('2000-01-01') |
+-----------------------+
|                730485 |               
+-----------------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> SELECT FROM_DAYS(1000000);
+--------------------+
| FROM_DAYS(1000000) |
+--------------------+
| 2737-11-28         |      
+--------------------+
1 row in set (0.02 sec)

mysql>

compared to

  • {{To day of CE|year=2000|month=01|monthday=01}} gives Expression error: Unexpected < operator. (too low by 364, why?)
  • {{To day of CE|year=2737|month=11|monthday=28}} gives Expression error: Unexpected < operator. (too low by 364, why?)

Note that

The UNIX command cal incorrectly lists 4 AD as a leap year (Vardi 1991);) (Cf. {{ifleapyear}})

Cf. Template talk:To day of CE.

In the evaluations at the right, we add the days for each month of the year, then add (year - 1) * 365 days, then add the leap days for the (year - 1) previous years as if Gregorian calendar rule applies to all, then add correction to get Julian calendar rule for years 1 to min(1582, year - 1), then subtract 1 day if year 4 (not leap year) is in previous years, then subtract 10 days if year > 1582.

Examples with valid input

code result
{{To day of CE}} Expression error: Unexpected < operator.
{{To day of CE|year=6000|month=01|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=4000|month=01|monthday=10}} Expression error: Unexpected < operator. Green tickY {{expr|(10) + 3999*365 + (999 - 39 + 9) + (15 - 3) - 1 - 10}} = 1460615
{{To day of CE|year=2737|month=11|monthday=28}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=01|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=Feb|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|2011|Feb|10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=03|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=Apr|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=May|monthday=10}} Expression error: Unexpected < operator. Green tickY {{expr|(31 + 28 + 31 + 30 + 10) + 2010*365 + (502 - 20 + 5) + (15 - 3) - 1 - 10}} = 734268
{{To day of CE|year=2011|month=June|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=07|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=08|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=09|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=10|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=11|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=12|monthday=10}} Expression error: Unexpected < operator.
{{To day of CE|year=2011|month=Dec|monthday=31}} Expression error: Unexpected < operator. Green tickY {{expr|(365) + 2010*365 + (502 - 20 + 5) + (15 - 3) - 1 - 10}} = 734503
{{To day of CE|year=2004|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=2005|month=Jan|monthday=01}} Expression error: Unexpected < operator.
{{To day of CE|year=2005|month=Dec|monthday=01}} Expression error: Unexpected < operator.
{{To day of CE|year=2004|month=Jan|monthday=20}} Expression error: Unexpected < operator.
{{To day of CE|year=2000|month=Feb|monthday=29}} Expression error: Unexpected < operator.
{{To day of CE|year=2000|month=Mar|monthday=20}} Expression error: Unexpected < operator.
{{To day of CE|year=2000|month=Dec|monthday=31}} Expression error: Unexpected < operator. Green tickY {{expr|(366) + 1999*365 + (499 - 19 + 4) + (15 - 3) - 1 - 10}} = 730486
{{To day of CE|year=1800|month=Jan|monthday=20}} Expression error: Unexpected < operator.
{{To day of CE|year=1730|month=Feb|monthday=20}} Expression error: Unexpected < operator.
{{To day of CE|year=1600|month=Mar|monthday=20}} Expression error: Unexpected < operator. Green tickY {{expr|(31 + 29 + 20) + 1599*365 + (399 - 15 + 3) + (15 - 3) - 1 - 10}} = 584103
{{To day of CE|year=1600|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=1582|month=Sep|monthday=30}} Expression error: Unexpected < operator.
{{To day of CE|year=1582|month=Oct|monthday=4}} Expression error: Unexpected < operator. Green tickY {{expr|(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 4) + 1581*365 + (395 - 15 + 3) + (15 - 3) - 1}} = 577736
{{To day of CE|year=1582|month=Oct|monthday=5}} To day of CE error: Invalid monthday (in 1582, Pope Gregory XIII decreed that the day after October 4, 1582 would be October 15, 1582)
{{To day of CE|year=1582|month=Oct|monthday=10}} To day of CE error: Invalid monthday (in 1582, Pope Gregory XIII decreed that the day after October 4, 1582 would be October 15, 1582)
{{To day of CE|year=1582|month=Oct|monthday=14}} To day of CE error: Invalid monthday (in 1582, Pope Gregory XIII decreed that the day after October 4, 1582 would be October 15, 1582)
{{To day of CE|year=1582|month=Oct|monthday=15}} Expression error: Unexpected < operator. Green tickY {{expr|(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 15) + 1581*365 + (395 - 15 + 3) + (15 - 3) - 1 - 10}} = 577737
{{To day of CE|year=1582|month=Oct|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=1582|month=Nov|monthday=30}} Expression error: Unexpected < operator.
{{To day of CE|year=1582|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=1400|month=Oct|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=1200|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=1112|month=Apr|monthday=23}} Expression error: Unexpected < operator. Green tickY {{expr|(31 + 29 + 31 + 23) + 1111*365 + (277 - 11 + 2) + (11 - 2) - 1}} = 405905
{{To day of CE|year=800|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=560|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=400|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=160|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=100|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=16|month=Dec|monthday=31}} Expression error: Unexpected < operator.
{{To day of CE|year=12|month=Dec|monthday=31}} Expression error: Unexpected < operator. Green tickY {{expr|(366) + 11*365 + 2 - 1}} = 4382
{{To day of CE|year=8|month=Dec|monthday=31}} Expression error: Unexpected < operator. Green tickY {{expr|(366) + 7*365 + 1 - 1}} = 2921
{{To day of CE|year=4|month=Dec|monthday=31}} Expression error: Unexpected < operator. Green tickY {{expr|(365) + 3*365}} = 1460
{{To day of CE|year=1|month=Dec|monthday=31}} Expression error: Unexpected < operator. Green tickY {{expr|(365)}} = 365

Examples with invalid input

code result
{{To day of CE|year=0|month=Sep|monthday=30}} To day of CE error: Year must be an integer in [1..10000]
{{To day of CE|year=50 BC|month=Sep|monthday=30}} To day of CE error: Year must be a nonzero unformatted integer in [1..10000]
{{To day of CE|year=-50|month=Sep|monthday=30}} To day of CE error: Year must be an integer in [1..10000]
{{To day of CE|year=0|month=Sep|monthday=30}} To day of CE error: Year must be an integer in [1..10000]
{{To day of CE|year=20000|month=Sep|monthday=30}} To day of CE error: Year must be an integer in [1..10000]
{{To day of CE|year=1600 AD|month=13|monthday=31}} To day of CE error: Year must be a nonzero unformatted integer in [1..10000]
{{To day of CE|year=1600|month=13|monthday=31}} To day of CE error: Invalid month
{{To day of CE|year=1600|month=0|monthday=31}} To day of CE error: Invalid month
{{To day of CE|year=1600|month=Hexember|monthday=31}} To day of CE error: Invalid month
{{To day of CE|year=1600|month=08|monthday=0}} To day of CE error: Monthday must be in [1..31] for August 1600
{{To day of CE|year=1600|month=08|monthday=32}} To day of CE error: Monthday must be in [1..31] for August 1600
{{To day of CE|year=1600|month=Sep|monthday=31}} To day of CE error: Monthday must be in [1..30] for September 1600
{{To day of CE|year=2000|month=Feb|monthday=30}} To day of CE error: Monthday must be in [1..29] for February 2000
{{To day of CE|year=1900|month=Feb|monthday=29}} To day of CE error: Monthday must be in [1..28] for February 1900

Code


{{ifint| {{{year|{{{1|{{LOCALYEAR}}}}}}}}
| {{#ifexpr: ( ( {{{year|{{{1|{{LOCALYEAR}}}}}}}} >= 1 ) and ( {{{year|{{{1|{{LOCALYEAR}}}}}}}} <= 10000 ) )
  | {{#iferror: {{monthnum|{{{month|{{{2|{{LOCALMONTH}}}}}}}}}}
    | {{error|To day of CE error: Invalid month}}  
    | {{#ifexpr: ( ( {{{monthday|{{{3|{{LOCALDAY}}}}}}}} >= 1 ) and ( {{{monthday|{{{3|{{LOCALDAY}}}}}}}} <= {{monthdays|{{{month|{{{2|{{LOCALMONTH}}}}}}}}|{{{year|{{{1|{{LOCALYEAR}}}}}}}}}} + 
      {{#ifexpr: ( ( {{{year|{{{1|{{LOCALYEAR}}}}}}}} = 1582 ) and ( {{monthnum|{{{month|{{{2|{{LOCALMONTH}}}}}}}}}} = 10 ) )
        | 10 <!-- even though Oct 5 to Oct 14 were skipped in 1582, monthday still went up to 31 -->
        | 0 
      }} ) )
      | {{#ifexpr: not ( ( {{{year|{{{1|{{LOCALYEAR}}}}}}}} = 1582 ) and ( {{monthnum|{{{month|{{{2|{{LOCALMONTH}}}}}}}}}} = 10 ) and ( {{{monthday|{{{3|{{LOCALDAY}}}}}}}} >= 5 ) and ( {{{monthday|{{{3|{{LOCALDAY}}}}}}}} <= 14 ) ) 
        | {{expr| {{yearday|{{{year|{{{1|{{LOCALYEAR}}}}}}}}|{{{month|{{{2|{{LOCALMONTH}}}}}}}}|{{{monthday|{{{3|{{LOCALDAY}}}}}}}} }} +
            ( (floor ( ({{{year|{{{1|{{LOCALYEAR}}}}}}}} - 1) / 400 ) ) * (100 * (3*365+366) - 3) ) +
              (floor ( {{min|1582|{{{year|{{{1|{{LOCALYEAR}}}}}}}} - 1}} / 400 ) * 3 ) + <!-- Julian calendar correction -->
            ( (floor ( ( ({{{year|{{{1|{{LOCALYEAR}}}}}}}} - 1) mod 400 ) / 100) ) * (25 * (3*365+366) - 1) ) +
              (floor ( ( {{min|1582|{{{year|{{{1|{{LOCALYEAR}}}}}}}} - 1}} mod 400 ) / 100 ) * 1 ) + <!-- Julian calendar correction -->
            ( (floor ( ( ({{{year|{{{1|{{LOCALYEAR}}}}}}}} - 1) mod 100 ) / 4) ) * (3*365+366) ) +
            ( ( ({{{year|{{{1|{{LOCALYEAR}}}}}}}} - 1) mod 4 ) * (365) ) -
            {{#ifexpr: {{{year|{{{1|{{LOCALYEAR}}}}}}}} > 4|1|0}} <!-- Year 4 was not a leap year. --> -
            {{#ifexpr: {{{year|{{{1|{{LOCALYEAR}}}}}}}} > 1582|10|0}} <!-- in 1582, Pope Gregory XIII decreed that the day after October 4, 1582 would be October 15, 1582 -->
          }}
        | {{error|To day of CE error: Invalid monthday (in 1582, Pope Gregory XIII decreed that the day after October 4, 1582 would be October 15, 1582)}} 
        }}  
      | {{error|To day of CE error: Monthday must be in [1..{{monthdays|{{{month|{{{2|{{LOCALMONTH}}}}}}}}|{{{year|{{{1|{{LOCALYEAR}}}}}}}}}}] for {{fullmonth|{{{month|{{{2|{{LOCALMONTH}}}}}}}}}} {{{year|{{{1|{{LOCALYEAR}}}}}}}} }}   
      }}
    }}       
  | {{error|To day of CE error: Year must be an integer in [1..10000]}}   
  }}
| {{error|To day of CE error: Year must be a nonzero unformatted integer in [1..10000]}}
}}

See also

  • {{daynum}} gives the weekday number (0 to 6) for (Sun to Sat)
  • {{day}} gives the standard three letter weekday abbreviation.
  • {{fullday}} gives the full weekday name.


  • {{monthnum}} gives the month number (padded left with 0 if necessary to get two decimal digits) (01 to 12)
  • {{month}} gives the standard three letter month abbreviation.
  • {{fullmonth}} gives the full month name.
  • {{days in month}} (or {{monthdays}}) gives the number of days in a month (for any year from 1 AD to 10000 AD)


  • {{yearday}} returns the day of year from year, month and monthday (for any year from 1 AD to 10000 AD)
  • {{ifleapyear}} or {{if leap year}} returns different values depending on whether a given year is a leap year or a common year (for any year from 1 AD to 10000 AD)
  • {{is leap year}} predicate function template returns 1 (if true) or 0 (if false) depending on whether a given year is a leap year or a common year (for any year from 1 AD to 10000 AD)
  • {{Century}} returns the century for any nonzero (negative or positive) year
  • {{Millennium}} returns the millennium for any nonzero (negative or positive) year


  • {{to day of CE}} returns the day of CE (Christ Era) from year, month and monthday (for any year from 1 AD to 10000 AD)
  • {{from day of CE}} returns year, month and monthday (for any year from 1 AD to 10000 AD) from the day of CE (Christ Era)


  • {{date}} for date mathematics (for any year from 1 AD to 10000 AD) (returns the date offset a specified number of days from a given date)
  • {{days between}} for date mathematics (for any years from 1 AD to 10000 AD) (returns the number of days between two dates)

Notes