Template:Year

From MEpedia, a crowd-sourced encyclopedia of ME and CFS science and history


template icon Template documentation[view] [edit] [history] [purge]

New code: more time formats accepted[edit source]

If last "word" is 4 digits then just use that.

<!--ends in 4 digits -->
{{#ifeq:{{str len|{{digits|{{last word|{{{1|}}}}}}}}}|4
|{{digits|{{last word|{{{1|}}}}}}}
|false}}<!--doesnt end in 4 digits -->

March 29, 2024 → 2019

Mar 29, 2024 → 2019

Mar 2024 → 2019

Usage[edit source]

{{year|string formatted as a valid date}}

{{year|}} - 2024

{{year|1999}} - 1999

{{year|1999-12-12}} - 1999

{{year|January 1999}} - 1999

{{year|15 January 1999}} - 1999

{{year|January 1, 1999}} - 1999

{{year|1-2-1990}} - 1990

{{year|1/2/1990}} - 1990

{{year|2239-10-23}} - 2239

{{year|October 10, 2019}} 2019

{{year|Oct 2019}} 2019

{{year|Oct 10, 2019}} 2019

Reports "Error" without a reason if given bad input:

{{year|1-14-1990}} Error
Reason for the error: there are not 14 months. {{year|61 January 1999}} 1999
Reason for the error: no month has 61 days. {{year|1 MyMonth 1999}} 1999
Reason for the error: there is no such month name. {{year|Some text which is not a date}} Error
Reason for the error: no date information to parse.

If used with a year range, it returns only the first match:

  • {{year|1999-2001}} 1999

This presently only works when the year range is specified with a hyphen -; if correctly given with an en dash -; which looks very similar, it reports an error (handling ranges is not the template's function).

If used without input, it simply outputs the current year:

  • {{year}} 2024
  • {{year|}} 2024

It can be cleanly substituted for this purpose. If fed invalid data when substituted, it produces a larger, red error.

If used when the value is already a year rather than a full date, it simply outputs the year:

  • {{year|2018}} 2018

See also[edit source]

  • Magic word: CURRENTTIMESTAMP includes both date and time
  • {{date}} – outputs the current date in various parameter-controlled formats
  • {{DATE}} – a subst-only convenience template used inside cleanup/dispute templates; |{{subst:DATE}} produces: |date=December 2018
  • Category:date and time templates – numerous date computing, formatting, annotating, and navigation templates

See also[edit source]