This site is supported by donations to The OEIS Foundation.

Template:Century

From OeisWiki
Jump to: navigation, search

The {{century}} date and time template returns the century in which the given year belongs, where the year defaults to local year of OEIS Wiki server. There was no year 0, since the ancient Greeks or Romans had no concept of zero. Thus the years 1 to 100 belong to century 1 (the 1st century AD,) ..., the years 1901 to 2000 belong to century 20 (the 20th century AD.) Conversely, the years -1 to -100 belong to century -1 (the 1st century BC,) ..., the years -1901 to -2000 belong to century -20 (the 20th century BC.)

Usage

{{century|year as a nonzero unformatted integer}}

or

{{century}} where year defaults to local year of OEIS Wiki server

Examples

Examples with valid input

code result
{{century}} 21
{{century|1}} 1
{{century|99}} 1
{{century|100}} 1
{{century|1899}} 19
{{century|1900}} 19
{{century|1901}} 20
{{century|1999}} 20
{{century|2000}} 20
{{century|2001}} 21
{{century|100999}} 1010
{{century|200000}} 2000
{{century|200001}} 2001
{{century|-1}} −1
{{century|-99}} −1
{{century|-100}} −1
{{century|-1899}} −19
{{century|-1900}} −19
{{century|-1901}} −20
{{century|-1999}} −20
{{century|-2000}} −20
{{century|-2001}} −21
{{century|-100999}} −1010
{{century|-200000}} −2000
{{century|-200001}} −2001

Examples with invalid input

code result
{{century|0}} Century error: There was no year 0 (the ancient Greeks or Romans had no concept of zero)
{{century|800.5}} Century error: Year must be a nonzero unformatted integer
{{century|2,000}} Century error: Year must be a nonzero unformatted integer
{{century|two thousand}} Century error: Year must be a nonzero unformatted integer
{{century|2000 ans}} Century error: Year must be a nonzero unformatted integer
{{century|year 2000}} Century error: Year must be a nonzero unformatted integer

Code

{{ifint| {{{1|{{LOCALYEAR}}}}}
| {{#ifexpr: ( {{{1|{{LOCALYEAR}}}}} ) != 0
  | {{#ifexpr: ( {{{1|{{LOCALYEAR}}}}} ) > 0
    | {{expr| floor ( ( ( {{{1|{{LOCALYEAR}}}}} ) - 1 ) / 100 ) + 1}}
    | {{expr| - (floor ( ( - ( {{{1|{{LOCALYEAR}}}}} ) - 1 ) / 100 ) + 1)}}
    }}
  | {{error|Century error: There was no year 0 (the ancient Greeks or Romans had no concept of zero)}}
  }}
| {{error|Century error: Year must be a nonzero unformatted integer}}
}}

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)