WP:Date math
Date math on Wikipedia is done with variables, templates and the #time
parser function.
In articles, it is almost always preferred to specify a specific static date for a statement or event rather than an automatically generated date. Wikipedia:As of describes how to properly specify such dates.
Current date and time
class="wikitable"
! Templates based on them ! What you see ! Comments |
| | {{CURRENTTIMESTAMP}} | |
rowspan="4" style="vertical-align: top" | | | {{CURRENTYEAR}} | |
{{tl|UTC}}
| {{UTC}} | also uses |
{{tl|CURRENTDATE}}
| {{CURRENTDATE}} | also uses |
{{tl|CURRENTJULIANDAY}}
| {{CURRENTJULIANDAY}} | current Julian day also uses |
rowspan="2" style="vertical-align: top" | | | {{CURRENTMONTH}} | |
{{tl|CURRENTMNTH}}
| {{CURRENTMNTH}} | trims leading zero |
rowspan="4" style="vertical-align: top" | | | {{CURRENTMONTHNAME}} | |
{{tl|Month+1}}
| {{Month+1}} | |
{{tl|Month-1}}
| {{Month-1}} | |
{{tl|Month-2}}
| {{Month-2}} | |
| | {{CURRENTDAY}} | day of month |
rowspan="4" style="vertical-align: top" | | | {{CURRENTDOW}} | day of week |
1 day}}
| {{#time:l |
1 day}}
| |
| {{#time:l}} | |
| {{#time:l|+1 day}} | |
colspan="4" style="background:#DDDDDD;" | Any variable or template with a resolution of smaller than one day should not be placed in articles. These variables only indicate when the article was parsed and cached; they may lag by many hours or even days compared to the time the page is viewed. |
| | {{CURRENTTIME}} | |
rowspan="3" style="vertical-align: top" | | | {{CURRENTHOUR}} | |
|{{#time:H|+1 hour}} | |
{{tl|Current hour}}
| {{Current hour}} | trims leading zero |
rowspan="3" style="vertical-align: top" | | | {{#time:i}} | |
{{tl|CURRENTMINUTE}}
| {{CURRENTMINUTE}} | |
{{tl|Current minute}}
| {{Current minute}} | trims leading zero |
rowspan="2" style="vertical-align: top" | | | {{#time:s}} | |
{{tl|CURRENTSECOND}}
| {{CURRENTSECOND}} | |
Computed date and time
class="wikitable"
! Template name ! Usage ! Output ! Comment |
rowspan="2" style="vertical-align: top" | {{tl|Ordinal date}}
| | {{Ordinal date|year=2007|month=03|day=15}} | returns ordinal date (day of year) |
| {{Ordinal date|year=2008|month=03|day=15}} | +1 due to leap year in 2008 |
rowspan="2" style="vertical-align: top" | {{tl|WEEKDAY}}
| | {{WEEKDAY|2009|08|25}} | returns day of week |
| {{WEEKDAYNAME|{{WEEKDAY|2009|08|25}}}} | |
rowspan="3" style="vertical-align: top" | {{tl|JULIANDAY}}
| | {{JULIANDAY|2009|08|25}} | |
| {{WEEKDAYNAME|{{JULIANDAY|2009|08|25}}}} | Note: 2455069 mod 7 = {{#expr:2455069 mod 7}} |
| {{JULIANDAY|{{CURRENTYEAR}}|{{CURRENTMONTH}}|{{CURRENTDAY}}}} | Nesting templates to get the value of the current Julian day with no decimal portion. Useful for date math between a set point and the current date. |
rowspan="2" style="vertical-align: top" | {{tl|JULIANDAY.TIMESTAMP}}
| | {{JULIANDAY.TIMESTAMP|2455069}} | same format as |
{{nowrap| | {{#time:D Y-m-d|{{JULIANDAY.TIMESTAMP|2455069}}}} | |
Julian dates or day numbers can be used for date calculations. A simple example follows:
- 90 days from 25 December 2006 is: {{#time:j F Y|{{JULIANDAY.TIMESTAMP|{{JULIANDAY|2006|12|25}}+90}}}}
- * Code:
{{#time:j F Y|{{JULIANDAY.TIMESTAMP|{{JULIANDAY|2006|12|25}}+90}}}} - 90 days from 25 December 2007 is: {{#time:j F Y|{{JULIANDAY.TIMESTAMP|{{JULIANDAY|2007|12|25}}+90}}}} (1 day less than first example due to leap year in 2008)
- * Code:
{{#time:j F Y|{{JULIANDAY.TIMESTAMP|{{JULIANDAY|2007|12|25}}+90}}}}
Fancy stuff
{{today cell}}
| {{tomorrow cell}} |
{{tl|today cell}}
| {{tl|tomorrow cell}} |