Template:Extract/doc
This template is under development, see talk.
This template can extract information from a date, or can format a date. Time units can be added to a date.
Syntax
{{extract|date|options}}
The following options are available:
add=periods to add• Add/subtract time units.fix=on• Adjust invalid time units.partial=on• Accept a year only, or a year and month only.show=code for what to display• Specifies what should be extracted (such asdayname), or how to format the date (such asmdy).
The date can be entered as the first parameter, or year/month/day components of the date can be entered in separate parameters.
A valid date must be specified. Dates are UTC—local times and time zones are not supported.
By default, the date is displayed in dmy format, for example, "12 November 2015".
A date can include an era or a time, and a variety of formats are accepted.
Examples of valid dates follow. Each row shows two equivalent methods of entering a date.
| A date as a single parameter | Components of a date in separate parameters |
|---|---|
{{extract|1900-02-01}} |
{{extract|1900|02|01}}
|
{{extract|1900-2-1 14:45}} |
{{extract|1900|2|1|14|45}}
|
{{extract|1 FEB 1900}} |
{{extract|1900|FEB|1}}
|
{{extract|February 1, 1900}} |
{{extract|1900|February|1}}
|
{{extract|Feb 1 1900 14:45}} |
{{extract|1900|Feb|1|14|45}}
|
{{extract|2:45 pm February 1 1900}} |
{{extract|1900|February|1|14|45}}
|
{{extract|1 February 1900 2:45 p.m.}} |
{{extract|1900|February|1|14|45}}
|
{{extract|BC 1 Feb 120}} |
{{extract|-119|2|1}}
|
Add
These time units can be added to a date:
yyearsmmonthsddayshhoursminminutessseconds
Multiple periods can be given, separated by spaces. There must be no space between a value and the code for the time unit.
A hyphen can be used for a negative value. Periods are added in the order given.
Examples:
{{extract|2004-04-03|add=28d}}→ 1 May 2004{{extract|2004-04-03|add=3m 28d}}→ 31 July 2004{{extract|2004-04-03|add=-3d}}→ 31 March 2004{{extract|2004-04-03|add=-912345d}}→ 5 May 495 BC{{extract|2004-04-03|add=250h}}→ 10:00 13 April 2004{{extract|2004-04-03|add=-2.5h}}→ 21:30 2 April 2004{{extract|2004-04-30|add=-2m}}→ 29 February 2004{{extract|2004-04-03|add=2y 3m 4d}}→ 7 July 2006{{extract|2004-04-03|add=5.75d}}→ 18:00 8 April 2004
Fix
By default, the date entered must be valid. If fix=on is used, units which are too large are "fixed". For example, 26 hours would be regarded as 1 day and 2 hours.
Entering a day as zero is regarded as the previous day (the last day of the previous month). The day before the previous day would be indicated with -1.
Similarly, entering a month as zero goes back one month, and entering -1 goes back two months.
Examples:
{{extract|2001|5|31|fix=on}}→ 31 May 2001 (no fix is required){{extract|2001|5|0|fix=on}}→ 30 April 2001{{extract|2001|5|-1|fix=on}}→ 29 April 2001{{extract|2001|125|-1000|fix=on}}→ 3 August 2008{{extract|2001|0|12|fix=on}}→ 12 December 2000{{extract|2016|3|0|fix=on}}→ 29 February 2016
Partial
If partial=on is used, the date may consist of a year only, or a year and month only. Addition is not supported for a partial date.
{{extract|2001|5|partial=on}}→ May 2001{{extract|2016|partial=on|show=isleapyear}}→ 1
Show
These are most of the show parameters that can be used:
| Parameter | Description |
|---|---|
show=year |
year |
show=month |
month (1 to 12) |
show=day |
day of month (1 to 31) |
show=hour |
hour (0 to 23) |
show=minute |
minute (0 to 59) |
show=second |
second (0 to 59) |
show=dayabbr |
abbreviated name of day of week |
show=dayname |
full name of day of week |
show=dayofweek |
day-of-week (0=Sunday to 6=Saturday) |
show=dayofweekiso |
day-of-week (1=Monday to 7=Sunday) |
show=dayofyear |
day-of-year (1 to 366) |
show=era |
an era code such as BC or BCE |
show=format |
code for the detected format of the input date (dmy, mdy, ymd) |
show=gsd |
Gregorian serial date |
show=juliandate |
Julian day |
show=isleapyear |
1 if the date is in a leap year; 0 otherwise |
show=monthabbr |
abbreviated name of month |
show=monthdays |
number of days in the month of the date |
show=monthname |
full name of month |
show=dmy |
show date as "day month year" (default) |
show=mdy |
show date as "month day, year" |
show=ymd |
show date as "year-month-day" |
Examples:
{{extract|1 Feb 2001}}→ 1 February 2001{{extract|FEB 1 2001}}→ 1 February 2001{{extract|2001-2-1}}→ 1 February 2001{{extract|1 Feb 2001|show=format}}→ dmy{{extract|FEB 1 2001|show=format}}→ mdy{{extract|2001-2-1|show=format}}→ ymd{{extract|1 Feb 2001|show=mdy}}→ February 1, 2001{{extract|1 Feb 2001|show=ymd}}→ 2001-02-01{{extract|June 30, 2001|show=dayname}}→ Saturday{{extract|June 30, 2001|show=dayofyear}}→ 181{{extract|2001-2-1|show=monthname}}→ February{{extract|2001-2-1|show=a %{dayname} in %{monthname} }}→ a Thursday in February