Template:Components
This template extracts numbers a, b, c from a string a-b-c, and a and b from a-b, and a from a. This can for example be applied to dates in the format y-m-d or d-m-y, months in the format y-m or m-y, and just years y, with a year range of ca. -1e14 to 1e14.
a-0-c gives the same results as a-c; also, not only 0-0-0 and 0-0 are not distinguished from each other, but also not from a single 0.
Examples
edit"{{components|2008-9-17|1}}"
gives "2008" [1]"{{components|2008-9-17|2}}"
gives "9" [2]"{{components|2008-9-17|3}}"
gives "17" [3]
"{{components|17-9-2008|1}}"
gives "17" [4]"{{components|17-9-2008|2}}"
gives "9" [5]"{{components|17-9-2008|3}}"
gives "2008" [6]
"{{components|2008-9|1}}"
gives "2008" [7]"{{components|2008-9|2}}"
gives "9" [8]"{{components|2008-9|3}}"
gives "" [9]
"{{components|2008|1}}"
gives "2008" [10]"{{components|2008|2}}"
gives "" [11]"{{components|2008|3}}"
gives "" [12]
Compare:
"{{#titleparts:9/17/2008|1|1|}}"
gives "9" [13]"{{#titleparts:9/17/2008|1|2|}}"
gives "17" [14]"{{#titleparts:9/17/2008|1|3|}}"
gives "2008" [15]
"{{#titleparts:9/17|1|1|}}"
gives "9" [16]"{{#titleparts:9/17|1|2|}}"
gives "17" [17]"{{#titleparts:9/17|1|3|}}"
gives "" [18]
"{{#titleparts:2008/9|1|1|}}"
gives "2008" [19]"{{#titleparts:2008/9|1|2|}}"
gives "9" [20]"{{#titleparts:2008/9|1|3|}}"
gives "" [21]
"{{#titleparts:2008|1|1|}}"
gives "2008" [22]"{{#titleparts:2008|1|2|}}"
gives "" [23]"{{#titleparts:2008|1|3|}}"
gives "" [24]
#time
editFunction #time
accepts dates like PHP's strtotime does. We consider here those with a dash. The examples show the resulting "y n d", which can be extracted separately too.
Full dates in the form d-m-y:
{{#time:Y n j|17-9-2008}}
→ 2008 9 17 [25]
Full and partial dates in the form y-m-d, y-m, and y:
{{#time:Y n j|2008-9-17}}
→ 2008 9 17 [26]{{#time:Y n j|108-9-17}}
→ 0108 9 17 [27]{{#time:Y n j|2008-9}}
→ 2008 9 1 [28] (current day of the month, not desired){{#time:Y n j|2008}}
→ 2008 12 25 [29] (year interpreted as time, gives current full date, not desired){{#time:Y n j|1999}}
→ 1999 12 25 [30] (current month and day of the month, not desired)
Thus #time
is suitable for full dates only, and from the year 100 only:
{{#time:Y n j|28-9-17}}
→ 2028 9 17 [31]
Applying #time to the result
editAfter applying this template to a string representing a partial or full date, it is known whether it is in the form of a full date (existing or not). If so, the function #time
can be usefully applied to check the existence of the date, to write it in a different format, and to find the weekday and the Gregorian serial day. If the year is outside the range that can be used by function #time
, a conversion can first be applied, as is done in Template:Gsd.
Example result:
- Wednesday 17 September 2008, gsd = 733302