Template:Age in days/doc: Difference between revisions

Agros urbe non clamaten
https://en.wikipedia.org/wiki/>Johnuniq
update to reflect changes since Module:Age used in April 2018‎
 
m 1 revision imported
 
(No difference)

Latest revision as of 18:10, 8 June 2025

{{#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.

        }}{{#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.

        }}{{#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.

| #default=

 {{#switch:

| =

TemplateStyles' src attribute must not be empty.

| #default=

 Lua error: expandTemplate: template loop detected.

}} }}

TemplateStyles' src attribute must not be empty.

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
1 }}||{{#switch:|1=|2=reflist-columns-2|#default=reflist-columns-3}} }}}}" {{#if:
   | {{#iferror: {{#ifexpr: 1 > 1 }} |style="column-width: {{{1}}};"}}
   | {{#if: |style="column-width: {{{colwidth}}};"}}
   }}>
  1. 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

 |

}}[[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|

 |

}} }}