User:Patrick/time

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

mw:Help:ParserFunctions##time

This parser function takes a date and/or time (default: the current date and time), and optionally performs additions and subtractions, and returns the result (or selected parts from it) in a specified format.

Time[edit]

The date/time object can be in any format accepted by PHP's strtotime() function.

  • {{#time:j F Y, G:i:s|now}} → 12 May 2021, 6:05:11 [1]
  • {{#time:j F Y, G:i:s|9 June 2010 7:34 120 hours 241 hours}} → 24 June 2010, 8:34:00 [2]
  • {{#time:j F Y, G:i:s|240 hours -120 hours}} → 17 May 2021, 6:05:11 [3]

The range of acceptable input is 1 January 0100 → 31 December 9999. Years in the range 1970-2069 can be abbreviated to two digits. Even with leading zeros they are interpreted as years in the mentioned range.

  • {{#time:j F Y, G:i:s| 15 April 0069 }} → 15 April 0069, 0:00:00 [4]
  • {{#time:j F Y, G:i:s| 15 April 0070 }} → 15 April 0070, 0:00:00 [5]
  • {{#time:j F Y, G:i:s| 15 April 10000 }}Error: Invalid time. [6]

Full or partial absolute dates can be specified; the function will fill in parts of the date that are not specified using the current values. However, the fill-in feature is not consistent; some parts are filled in using the current values, others are not:

  • {{#time:j F Y, G:i:s|240809}} → 13 May 2021, 0:08:09 [7]
  • {{#time:j F Y, G:i:s|076009}}Error: Invalid time. [8]
  • {{#time:j F Y, G:i:s|070860}} → 12 May 2021, 7:09:00 [9]
  • {{#time:j F Y, G:i:s|10203}}Error: Invalid time. [10]
  • {{#time:j F Y, G:i:s|0809}} → 12 May 0809, 0:00:00 [11]
  • {{#time:j F Y, G:i:s|2409}} → 12 May 2409, 0:00:00 [12]
  • {{#time:j F Y, G:i:s|0860}} → 12 May 0860, 0:00:00 [13]
  • {{#time:j F Y, G:i:s|708}}Error: Invalid time. [14]
  • {{#time:j F Y, G:i:s|07}}Error: Invalid time. [15]
  • {{#time:j F Y, G:i:s|jun}} → 12 June 2021, 0:00:00 [16]
  • {{#time:j F Y, G:i:s|jun2}} → 2 June 2021, 0:00:00 [17]
  • {{#time:j F Y, G:i:s|jun22}} → 22 June 2021, 0:00:00 [18]
  • {{#time:j F Y, G:i:s|jun222}}Error: Invalid time. [19]
  • {{#time:j F Y, G:i:s|jun}} → 12 June 2021, 0:00:00 [20]
  • {{#time:j F Y, G:i:s|jun}} → 12 June 2021, 0:00:00 [21]
  • {{#time:j F Y, G:i:s|jun}} → 12 June 2021, 0:00:00 [22]
  • {{#time:j F Y, G:i:s|jun}} → 12 June 2021, 0:00:00 [23]
  • {{#time:j F Y, G:i:s|jun}} → 12 June 2021, 0:00:00 [24]
  • {{#time:j F Y, G:i:s|7}}Error: Invalid time. [25]
  • {{#time:j F Y, G:i:s|7}}Error: Invalid time. [26]
  • {{#time:j F Y, G:i:s|8 June 2009 7:34}} → 8 June 2009, 7:34:00 [27]
  • {{#time:j F Y, G:i:s|June 2009 7:34}} → 1 June 2009, 7:34:00 [28]
  • {{#time:j F Y, G:i:s|8 2009 7:34}}Error: Invalid time. [29]
  • {{#time:j F Y, G:i:s|8 June 7:34}}Error: Invalid time. [30]
  • {{#time:j F Y, G:i:s|8 June 2009}} → 8 June 2009, 0:00:00 [31]
  • {{#time:j F Y, G:i:s|June 2009}} → 1 June 2009, 0:00:00 [32]
  • {{#time:j F Y, G:i:s|8 June}} → 8 June 2021, 0:00:00 [33]
  • {{#time:j F Y, G:i:s|8 2009}}Error: Invalid time. [34]
  • {{#time:j F Y, G:i:s|2009 7:34}}Error: Invalid time. [35]
  • {{#time:j F Y, G:i:s|June 7:34}} → 12 June 2021, 7:34:00 [36]
  • {{#time:j F Y, G:i:s|8 7:34}}Error: Invalid time. [37]
  • {{#time:j F Y, G:i:s|9}}Error: Invalid time. [38]
  • {{#time:j F Y, G:i:s|June}} → 12 June 2021, 0:00:00 [39]
  • {{#time:j F Y, G:i:s|2009}} → 12 May 2009, 0:00:00 [40]
  • {{#time:j F Y, G:i:s|7:34}} → 12 May 2021, 7:34:00 [41]
  • {{#time:j F Y, G:i:s|08 June 2009 7:34}} → 8 June 2009, 7:34:00 [42]
  • {{#time:j F Y, G:i:s|June 2009 7:34}} → 1 June 2009, 7:34:00 [43]
  • {{#time:j F Y, G:i:s|08 2009 7:34}}Error: Invalid time. [44]
  • {{#time:j F Y, G:i:s|08 June 7:34}}Error: Invalid time. [45]
  • {{#time:j F Y, G:i:s|08 June 2009}} → 8 June 2009, 0:00:00 [46]
  • {{#time:j F Y, G:i:s|June 2009}} → 1 June 2009, 0:00:00 [47]
  • {{#time:j F Y, G:i:s|08 June}} → 8 June 2021, 0:00:00 [48]
  • {{#time:j F Y, G:i:s|08 2009}}Error: Invalid time. [49]
  • {{#time:j F Y, G:i:s|2009 7:34}}Error: Invalid time. [50]
  • {{#time:j F Y, G:i:s|June 7:34}} → 12 June 2021, 7:34:00 [51]
  • {{#time:j F Y, G:i:s|08 7:34}}Error: Invalid time. [52]
  • {{#time:j F Y, G:i:s|09}}Error: Invalid time. [53]
  • {{#time:j F Y, G:i:s|June}} → 12 June 2021, 0:00:00 [54]
  • {{#time:j F Y, G:i:s|2009}} → 12 May 2009, 0:00:00 [55]
  • {{#time:j F Y, G:i:s|7:34}} → 12 May 2021, 7:34:00 [56]
  • {{#time:j F Y, G:i:s|8 June 2009 734}}Error: Invalid time. [57]
  • {{#time:j F Y, G:i:s|June 2009 734}}Error: Invalid time. [58]
  • {{#time:j F Y, G:i:s|8 2009 734}}Error: Invalid time. [59]
  • {{#time:j F Y, G:i:s|8 June 734}} → 8 June 0734, 0:00:00 [60]
  • {{#time:j F Y, G:i:s|8 June 2009}} → 8 June 2009, 0:00:00 [61]
  • {{#time:j F Y, G:i:s|June 2009}} → 1 June 2009, 0:00:00 [62]
  • {{#time:j F Y, G:i:s|8 June}} → 8 June 2021, 0:00:00 [63]
  • {{#time:j F Y, G:i:s|8 2009}}Error: Invalid time. [64]
  • {{#time:j F Y, G:i:s|2009 734}}Error: Invalid time. [65]
  • {{#time:j F Y, G:i:s|June 734}}Error: Invalid time. [66] ("June 73", 2004)
  • {{#time:j F Y, G:i:s|8 734}}Error: Invalid time. [67]
  • {{#time:j F Y, G:i:s|9}}Error: Invalid time. [68]
  • {{#time:j F Y, G:i:s|June}} → 12 June 2021, 0:00:00 [69]
  • {{#time:j F Y, G:i:s|2009}} → 12 May 2009, 0:00:00 [70]
  • {{#time:j F Y, G:i:s|734}}Error: Invalid time. [71]
  • {{#time:j F Y, G:i:s|08 June 2009 734}}Error: Invalid time. [72]
  • {{#time:j F Y, G:i:s|June 2009 734}}Error: Invalid time. [73]
  • {{#time:j F Y, G:i:s|08 2009 734}}Error: Invalid time. [74]
  • {{#time:j F Y, G:i:s|08 June 734}} → 8 June 0734, 0:00:00 [75]
  • {{#time:j F Y, G:i:s|08 June 2009}} → 8 June 2009, 0:00:00 [76]
  • {{#time:j F Y, G:i:s|June 2009}} → 1 June 2009, 0:00:00 [77]
  • {{#time:j F Y, G:i:s|08 June}} → 8 June 2021, 0:00:00 [78]
  • {{#time:j F Y, G:i:s|08 2009}}Error: Invalid time. [79]
  • {{#time:j F Y, G:i:s|2009 734}}Error: Invalid time. [80]
  • {{#time:j F Y, G:i:s|June 734}}Error: Invalid time. [81]
  • {{#time:j F Y, G:i:s|08 734}}Error: Invalid time. [82]
  • {{#time:j F Y, G:i:s|09}}Error: Invalid time. [83]
  • {{#time:j F Y, G:i:s|June}} → 12 June 2021, 0:00:00 [84]
  • {{#time:j F Y, G:i:s|2009}} → 12 May 2009, 0:00:00 [85]
  • {{#time:j F Y, G:i:s|734}}Error: Invalid time. [86]
  • {{#time:j F Y, G:i:s|9 June 2010 :34}}Error: Invalid time. [87]
  • {{#time:j F Y, G:i:s|9 June 2010 7}}Error: Invalid time. [88]


  • {{#time:j F Y, G:i:s| January 1 }} → 1 January 2021, 0:00:00 [89]
  • {{#time:j F Y, G:i:s| February 2007 }} → 1 February 2007, 0:00:00 [90] Goes to the start of the month, not the current day.

A four-digit number is interpreted as hours and minutes if possible, and otherwise as year:

  • {{#time:j F Y, G:i:s| 1959 }} → 12 May 1959, 0:00:00 [91]
  • {{#time:j F Y, G:i:s| 1960 }} → 12 May 1960, 0:00:00 [92]

A six-digit number is interpreted as hours, minutes and seconds if possible, but otherwise as an error (not, for instance, a year and month):

  • {{#time:j F Y, G:i:s| 195909 }} → 12 May 2021, 19:59:09 [93]
  • {{#time:j F Y, G:i:s| 196009 }}Error: Invalid time. [94]

Unix timestamp: pre-pend an @ symbol:

  • {{#time:j F Y, G:i:s| @1620799515 }} → 12 May 2021, 6:05:15 [95]

Year[edit]

  • {{#time:j F Y, G:i:s U|100}}Error: Invalid time. [96]
  • {{#time:j F Y, G:i:s U|101}}Error: Invalid time. [97]
  • {{#time:j F Y, G:i:s U|160}}Error: Invalid time. [98]
  • {{#time:j F Y, G:i:s U|260}}Error: Invalid time. [99]
  • {{#time:j F Y, G:i:s U|360}}Error: Invalid time. [100]
  • {{#time:j F Y, G:i:s U|460}}Error: Invalid time. [101]
  • {{#time:j F Y, G:i:s U|560}}Error: Invalid time. [102]
  • {{#time:j F Y, G:i:s U|660}}Error: Invalid time. [103]
  • {{#time:j F Y, G:i:s U|760}}Error: Invalid time. [104]
  • {{#time:j F Y, G:i:s U|860}}Error: Invalid time. [105]
  • {{#time:j F Y, G:i:s U|960}}Error: Invalid time. [106]
  • {{#time:j F Y, G:i:s U|1060}} → 12 May 1060, 0:00:00 -28705449600 [107]
  • {{#time:j F Y, G:i:s U|1160}} → 12 May 1160, 0:00:00 -25549776000 [108]
  • {{#time:j F Y, G:i:s U|1260}} → 12 May 1260, 0:00:00 -22394016000 [109]
  • {{#time:j F Y, G:i:s U|1360}} → 12 May 1360, 0:00:00 -19238342400 [110]
  • {{#time:j F Y, G:i:s U|1460}} → 12 May 1460, 0:00:00 -16082668800 [111]
  • {{#time:j F Y, G:i:s U|1560}} → 12 May 1560, 0:00:00 -12926995200 [112]
  • {{#time:j F Y, G:i:s U|1660}} → 12 May 1660, 0:00:00 -9771235200 [113]
  • {{#time:j F Y, G:i:s U|1760}} → 12 May 1760, 0:00:00 -6615561600 [114]
  • {{#time:j F Y, G:i:s U|1860}} → 12 May 1860, 0:00:00 -3459888000 [115]
  • {{#time:j F Y, G:i:s U|1960}} → 12 May 1960, 0:00:00 -304214400 [116]
  • {{#time:j F Y, G:i:s U|16}}Error: Invalid time. [117]
  • {{#time:j F Y, G:i:s U|60}}Error: Invalid time. [118]
  • {{#time:j F Y, G:i:s U|99}}Error: Invalid time. [119]
  • {{#time:j F Y, G:i:s U|1999}} → 12 May 1999, 0:00:00 926467200 [120]
  • {{#time:j F Y, G:i:s U|2400}} → 12 May 2400, 0:00:00 13580870400 [121]
  • {{#time:j F Y, G:i:s U|9999}} → 12 May 9999, 0:00:00 253382083200 [122]

Year and month[edit]

  • {{#time:j F Y, G:i:s U|jun8}} → 8 June 2021, 0:00:00 1623110400 [123]

Month[edit]

  • {{#time:j F Y, G:i:s U|jun}} → 12 June 2021, 0:00:00 1623456000 [124]

Year, month and day[edit]

  • {{#time:j F Y, G:i:s U|1-2-3}} → 3 February 2001, 0:00:00 981158400 [125]
  • {{#time:j F Y, G:i:s U|1-2-2003}} → 1 February 2003, 0:00:00 1044057600 [126]
  • {{#time:j F Y, G:i:s U|1/2/3}} → 2 January 2003, 0:00:00 1041465600 [127]
  • {{#time:j F Y, G:i:s U|2008/2/3}} → 3 February 2008, 0:00:00 1201996800 [128]
  • Expression error: Unrecognized word "january".

Output selection and format[edit]

Characters in the formatting string that are not recognised (including spaces, link brackets, and formatting apostrophs) are passed through unaltered. There are also two ways to escape characters within the formatting string:

  1. A backslash followed by a formatting character is interpreted as a single literal character
  2. characters enclosed in double quotes are considered literal characters, and the quotes are removed

In addition, the digraph xx is interpreted as a single literal "x". However, in view of the limitation that the total length of the format strings of the expanded calls of #time is limited to 6000 characters [129], it can be useful to avoid literal characters (even spaces), and use multiple calls instead. For example, instead of {{#time:d F Y|20100912123456}} one can use {{#time:d|20100912123456}} {{#time:F|20100912123456}} {{#time:Y|20100912123456}}. If the argument is the result of some expansion, multiple counts for that are avoided with a template containing e.g. {{#time:d|{{{1}}}}} {{#time:F|{{{1}}}}} {{#time:Y|{{{1}}}}}. This reduces the time-format count from 5 to 3, and if a similar template is used for e.g. F Y then this may give even further reduction due to additional reuse: once d F Y and once F Y reduces the count from from 8 to 4.

Code Description Current output
Year
Y 4-digit year. 2021
y 2-digit year. 21
L 1 or 0 whether it's a leap year or not 0
o ¹ ISO-8601 year number. ² 2021 ³

¹ Requires PHP 5.1.0 and newer and rev:45208
² This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.
³ Will output literal o if ¹ not fulfilled

Month
n Month index, not zero-padded. 5
m Month index, zero-padded. 05
M An abbreviation of the month name, in the site language. May
F The full month name in the site language. May
Week
W ISO 8601 week number, zero-padded. 19
Day
j Day of the month, not zero-padded. 12
d Day of the month, zero-padded. 12
z Day of the year (January 1 = 0)
[[#ref_{{{1}}}|^]]  To get the ISO day of the year add 1.
131
D An abbreviation for the day of the week. Rarely internationalised. Wed
l The full weekday name. Rarely internationalised. Wednesday
N ISO 8601 day of the week (Monday = 1, Sunday = 7). 3
w number of the day of the week (Sunday = 0, Saturday = 6). 3
Hour
a "am" during the morning (00:00:00 → 11:59:59), "pm" otherwise (12:00:00 → 23:59:59) am
A Uppercase version of a above. AM
g Hour in 12-hour format, not zero-padded. 6
h Hour in 12-hour format, zero-padded. 06
G Hour in 24-hour format, not zero-padded. 6
H Hour in 24-hour format, zero-padded. 06
Minutes and seconds
i Minutes past the hour, zero-padded. 05
s Seconds past the minute, zero-padded. 15
U Seconds since January 1 1970 00:00:00 GMT. 1620799515
Miscellaneous
L 1 if this year is a leap year in the Gregorian calendar, 0 otherwise 0
t Number of days in the current month. 31
c ISO 8601 formatted date, equivalent to Y-m-dTH:i:s+00:00. 2021-05-12T06:05:15+00:00
r RFC 2822 formatted date, equivalent to D, j M Y H:i:s +0000, with weekday name and month name not internationalised. Wed, 12 May 2021 06:05:15 +0000

Foreign[edit]

Code Description Current output
xg Output the full month name in the genitive form for site languages that distinguish between genitive and nominative forms. For Polish:

(nominative)

{{#time:d F Y|20 June 2010}} → 20 czerwiec 2010

(genitive)

{{#time:d xg Y|20 June 2010}} → 20 czerwca 2010

Non-Gregorian calendars
Iranian
xij Day of the month 22
xiF Full month name Ordibehesht
xin Month index 2
xiY Full year 1400
Hebrew
xjj Day of the month 1
xjF Full month name Sivan
xjx Genitive form of the month name Sivan
xjn Month number 9
xjY Full year 5781
Thai solar
xkY Full year 2564
Flags
xn Format the next numeric code as a raw ASCII number. In the Hindi language, {{#time:H, xnH}} produces ०६, 06
xN Like xn, but as a toggled flag, which endures until the end of the string or until the next appearance of xN in the string.
xr Format the next number as a roman numeral. Only works for numbers up to 3000. {{#time:xrY}} → MMXXI