Template:Date formatter: Difference between revisions
| IssuePress (talk | contribs) No edit summary | IssuePress (talk | contribs)  No edit summary | ||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| <includeonly> | <includeonly> | ||
| {{#if:{{{ | {{#if:{{{2|}}}| | ||
|    {{#ifeq:{{{ |    {{#ifeq:{{#time:Y|{{{1}}}}}|{{#time:Y|{{{2}}}}}| | ||
|      {{#time:F j, Y|{{{ |      {{#ifeq:{{#time:F|{{{1}}}}}|{{#time:F|{{{2}}}}}| | ||
|      |{{#time:F j, Y|{{{ |       {{#ifeq:{{{1}}}|{{{2}}}| | ||
|    }} |         {{#time:F j, Y|{{{1}}}}}| | ||
|    | |         {{#time:F j|{{{1}}}}} – {{#time:j, Y|{{{2}}}}} | ||
|       }}| | |||
|       {{#time:F j|{{{1}}}}} – {{#time:F j, Y|{{{2}}}}} | |||
|      }}| | |||
|     {{#time:F j, Y|{{{1}}}}} – {{#time:F j, Y|{{{2}}}}} | |||
|    }}| | |||
|    {{#time:F j, Y|{{{1}}}}} | |||
| }} | }} | ||
| </includeonly><noinclude> | |||
| </includeonly> | This template compares two dates (<code>start date</code> and <code>end date</code>) and formats the output: | ||
| <noinclude> | * If the dates are the same, it displays the single date. | ||
| This  | * If the dates are different, it displays a range in the format: "December 7 – 9, 2024". | ||
| * If <code>end date</code> is missing, it outputs the start date, but formatted as string. | |||
| ==Usage== | ==Usage== | ||
| he template is designed to work with variables, such as <code><start date</code> and <code>end date</code>>: | |||
| <pre> | <pre> | ||
| {{Date  | {{Date formatter |<start date>|<end date>}} | ||
| </pre> | </pre> | ||
| ===Examples | === Parameters === | ||
| {| class="wikitable" | |||
| ! Parameter !! Description !! Example | |||
| |- | |||
| | '''1''' (required) || The starting date in the format <code>YYYY/MM/DD</code>. || <code>2024/12/07</code> | |||
| |- | |||
| | '''2''' (optional) || The ending date in the format <code>YYYY/MM/DD</code>. If not provided, the template will output "Invalid input." || <code>2024/12/09</code> | |||
| |} | |||
| ==Examples== | |||
| The following examples use hard-coded dates, for examples sake.   | The following examples use hard-coded dates, for examples sake.   | ||
| <pre> | <pre> | ||
| {{Date  | {{Date formatter|2024/12/07|2024/12/07}} | ||
| </pre> | |||
| {{Date formatter|2024/12/07|2024/12/07}} | |||
| <pre> | |||
| {{Date formatter |2024/12/07 |2024/12/09}} | |||
| </pre> | |||
| {{Date formatter |2024/12/07 |2024/12/09}} | |||
| <pre> | |||
| {{Date formatter |2024/12/07}} | |||
| </pre> | </pre> | ||
| {{Date  | {{Date formatter |2024/12/07}} | ||
| <pre> | <pre> | ||
| {{Date  | {{Date formatter|2024/12/31|2025/01/01}} | ||
| </pre> | </pre> | ||
| {{Date  | {{Date formatter|2024/12/31|2025/01/01}} | ||
| </noinclude> | </noinclude> | ||
Latest revision as of 03:34, 13 December 2024
This template compares two dates (start date and end date) and formats the output:
- If the dates are the same, it displays the single date.
- If the dates are different, it displays a range in the format: "December 7 – 9, 2024".
- If end dateis missing, it outputs the start date, but formatted as string.
Usage
he template is designed to work with variables, such as <start date and end date>:
{{Date formatter |<start date>|<end date>}}
Parameters
| Parameter | Description | Example | 
|---|---|---|
| 1 (required) | The starting date in the format YYYY/MM/DD. | 2024/12/07 | 
| 2 (optional) | The ending date in the format YYYY/MM/DD. If not provided, the template will output "Invalid input." | 2024/12/09 | 
Examples
The following examples use hard-coded dates, for examples sake.
{{Date formatter|2024/12/07|2024/12/07}}
December 7, 2024
{{Date formatter |2024/12/07 |2024/12/09}}
December 7 – 9, 2024
{{Date formatter |2024/12/07}}
December 7, 2024
{{Date formatter|2024/12/31|2025/01/01}}
December 31, 2024 – January 1, 2025