Template:Age in days/doc
{{#switch:<translate></translate> | = {{#if:{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}
|
{{#ifeq:show |show
| TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon book-ltr.svg | <translate> This is a documentation [[<tvar name=2>Special:MyLanguage/Help:Subpages</tvar>|subpage]] for <tvar name=1>Template:Age in days</tvar>.</translate> {{#if: |<translate> It contains usage information, [[<tvar name=7>Special:MyLanguage/Help:Categories</tvar>|categories]] and other content that is not part of the original <tvar name=1>{{{text1}}}</tvar>.</translate> |<translate> It contains usage information, [[<tvar name=7>Special:MyLanguage/Help:Categories</tvar>|categories]] and other content that is not part of the original <tvar name=1>Template</tvar> page.</translate>}} |
}}{{#if: | | {{#ifexist:Template:Age in days | [[Category:{{#switch:Template | Template | Project = Template | Module = Module | User = User | #default = MediaWiki }} documentation pages{{#translation:}}]] | [[Category:Documentation subpages without corresponding pages{{#translation:}}]] }} }} | }}
| #default=
{{#switch:
| = {{#if:{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}
|
{{#ifeq:show |show
| TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon book-ltr.svg | This is a documentation subpage for Template:Age in days. {{#if: |It contains usage information, categories and other content that is not part of the original {{{text1}}}. |It contains usage information, categories and other content that is not part of the original Template page.}} |
}}{{#if: | | {{#ifexist:Template:Age in days | [[Category:{{#switch:Template | Template | Project = Template | Module = Module | User = User | #default = MediaWiki }} documentation pages{{#translation:}}]] | [[Category:Documentation subpages without corresponding pages{{#translation:}}]] }} }} | }}
| #default=
Lua error: expandTemplate: template loop detected.
}} }} {{#switch:<translate></translate> | =
TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon alert-warning.svg | {{#switch:Template
|Module={{#if:2348 |<translate> This Lua module is used on approximately <tvar name=5>2,348</tvar> pages.</translate> |<translate> This Lua module is used on many pages.</translate> }} |#default={{#if:2348 |<translate> This template is used on approximately <tvar name=5>2,348</tvar> pages.</translate> |<translate> This template is used on many pages.</translate> }} }} {{#switch:Template |Module=<translate> To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its [[<tvar name=4>{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/sandbox</tvar>|/sandbox]] or [[<tvar name=5>{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/testcases</tvar>|/testcases]] subpages.</translate> |#default=<translate> To avoid large-scale disruption and unnecessary server load, any changes to this template should first be tested in its [[<tvar name=4>{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/sandbox</tvar>|/sandbox]] or [[<tvar name=5>{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/testcases</tvar>|/testcases]] subpages or in your own [[<tvar name=9>Special:MyLanguage/Help:Subpages#Use of subpages</tvar>|user subpage]].</translate> }} <translate> The tested changes can then be added to this page in one single edit.</translate> {{#if: |<translate> Please consider discussing any changes at <tvar name=2>[[Template:Trim]]</tvar> before implementing them.</translate> |<translate> Please consider discussing any changes on the [[<tvar name=3>{{#switch:doc|doc|sandbox=Template talk:Age in days|#default=Template talk:Age in days/doc}}</tvar>|talk page]] before implementing them.</translate>}} |
| #default=
{{#switch:
| =
TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon alert-warning.svg | {{#switch:Template
|Module={{#if:2348 |This Lua module is used on approximately 2,348 pages. |This Lua module is used on many pages. }} |#default={{#if:2348 |This template is used on approximately 2,348 pages. |This template is used on many pages. }} }} {{#switch:Template |Module=To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its [[{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/sandbox|/sandbox]] or [[{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/testcases|/testcases]] subpages. |#default=To avoid large-scale disruption and unnecessary server load, any changes to this template should first be tested in its [[{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/sandbox|/sandbox]] or [[{{#switch:doc|doc|sandbox=Template:Age in days|#default=Template:Age in days/doc}}/testcases|/testcases]] subpages or in your own user subpage. }} The tested changes can then be added to this page in one single edit. {{#if: |Please consider discussing any changes at [[Template:Trim]] before implementing them. |Please consider discussing any changes on the [[{{#switch:doc|doc|sandbox=Template talk:Age in days|#default=Template talk:Age in days/doc}}|talk page]] before implementing them.}} |
| #default=
Lua error: expandTemplate: template loop detected.
}} }}
TemplateStyles' src
attribute must not be empty.
Lua logo | Uses Lua: |
This template returns the number of days between two dates. Dates may be input either as full dates or as year, month and day.
Usage
Full dates
To use, type:
{{age in days|date1|date2}}
(number of days between dates 1 and 2), {{age in days|date1}}
(number of days since date 1) or {{age in days||date2}}
(number of days until date 2)
Examples:
{{age in days|19 Aug 2008|4 Sep 2010}}
gives <?php $now = time(); // or your date as well $your_date = strtotime("2010-01-01"); $datediff = $now - $your_date; echo floor($datediff/(60*60*24));
?>
{{age in days|27 May 2002}}
gives <?php $now = time(); // or your date as well $your_date = strtotime("2010-01-01"); $datediff = $now - $your_date; echo floor($datediff/(60*60*24));
?>
{{age in days||{{#time:j M Y|+ 15 months}}}}
gives <?php $now = time(); // or your date as well $your_date = strtotime("2010-01-01"); $datediff = $now - $your_date; echo floor($datediff/(60*60*24));
?>
Year, month and day
To use, type:
{{age in days|year1|month1|day1|year2|month2|day2}}
(number of days between dates 1 and 2), {{age in days|year1|month1|day1}}
(number of days since date 1) or {{age in days||||year2|month2|day2}}
(number of day until date 2)
Or with named parameters:
{{age in days|month1= |day1= |year1= |month2= |day2= | year2= }}
(number of days between dates 1 and 2), {{age in days|month1= |day1= |year1= }}
(number of days since date 1) or {{age in days|month2= |day2= | year2= }}
(number of day until date 2)
Examples:
{{age in days|2007|5|24|2008|4|23}} |
gives <?php
$now = time(); // or your date as well $your_date = strtotime("2010-01-01"); $datediff = $now - $your_date; echo floor($datediff/(60*60*24)); ?> |
{{age in days|2007|5|24}} |
gives <?php
$now = time(); // or your date as well $your_date = strtotime("2010-01-01"); $datediff = $now - $your_date; echo floor($datediff/(60*60*24)); ?> |
Sorting
By adding |{{SAFESUBST:#if:sortable|sortable=}}on
a sort key will be added to the output for use in sortable tables.
Formatting
Three styles of formatting are possible.
format=}}raw gives unformatted numbers with hyphens as minus signs[1] (for use in further calculations). format=}}commas gives numbers formatted with commas and true minus signs.
For reasons of retrospective compatibility, the default when inputting dates as year, month and day is |{{SAFESUBST:#if:format|format=}}raw
; however when inputting dates in full it is |{{SAFESUBST:#if:format|format=}}commas
.
- Note
| {{#iferror: {{#ifexpr: 1 > 1 }} |style="column-width: {{{1}}};"}} | {{#if: |style="column-width: {{{colwidth}}};"}} }}>
- ↑ Negative days will occur if the first date is after the second.
Showing the unit
The default is not to show units. To show the unit ("day", days" or "d") use |{{SAFESUBST:#if:show unit|show unit=}}
.
show unit=}}abbr adds "d" after the number of days. show unit=}}full adds "day" or "days" after the number of days as appropriate.
See also
- Wikipedia:Age calculation templates
- {{{{#ifeq:Template:Duration in days|
|
}}[[Special:MyLanguage/Template:Duration in days|{{#if: |{{{2}}} |{{#ifexist:Translations:{{#if:Template|Template:}}Duration in days/Page display title/en
|{{#ifexpr:{{#if:0|1|0}} and 10!=0 |{{#ifeq:en|en |Duration in days |{{#if: |{{#ifeq:0|0 | | String Module Error: Target string is empty }} |{{#if:{{ Template:TNTN | nsp = 0 }} |{{ Template:TNTN | nsp = 0 }} |Template:Duration in days }} }} }} |{{ Template:TNTN }} }} |{{#if:0 |{{#if:Duration in days |Duration in days |Template:Duration in days }} |Template:Duration in days }}
}}}}]]{{#ifeq:Template:Duration in days|
|
}}
}}- {{{{#ifeq:Template:Time ago|
|
}}[[Special:MyLanguage/Template:Time ago|{{#if: |{{{2}}} |{{#ifexist:Translations:{{#if:Template|Template:}}Time ago/Page display title/en
|{{#ifexpr:{{#if:0|1|0}} and 10!=0 |{{#ifeq:en|en |Time ago |{{#if: |{{#ifeq:0|0 | | String Module Error: Target string is empty }} |{{#if:{{ Template:TNTN | nsp = 0 }} |{{ Template:TNTN | nsp = 0 }} |Template:Time ago }} }} }} |{{ Template:TNTN }} }} |{{#if:0 |{{#if:Time ago |Time ago |Template:Time ago }} |Template:Time ago }}
}}}}]]{{#ifeq:Template:Time ago|
|
}}
}}