Template:Date-calc: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
{{#if: {{{date|}}} | |
{{#if: {{{date|}}} | |
||
{{#ifeq: {{{operation|}}} | add | |
{{#ifeq: {{{operation|}}} | add | |
||
{{#time: j F Y | {{{date}}} + {{{days|0}}} days + {{{weeks|0}}} weeks + {{{months|0}}} months }} |
|||
| 1 = {{#time: jS F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| 21 = {{#time: jS F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| 31 = {{#time: jS F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| 2 = {{#time: jnd F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| 22 = {{#time: jnd F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| 3 = {{#time: jrd F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| 23 = {{#time: jrd F Y | {{{date}}} + {{{days|1}}} days }} |
|||
| #default = {{#time: jth F Y | {{{date}}} + {{{days|1}}} days }} |
|||
}} |
|||
}} |
}} |
||
{{#ifeq: {{{operation|}}} | subtract | |
{{#ifeq: {{{operation|}}} | subtract | |
||
{{#time: j F Y | {{{date}}} - {{{days|0}}} days - {{{weeks|0}}} weeks - {{{months|0}}} months }} |
|||
| 1 = {{#time: jS F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| 21 = {{#time: jS F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| 31 = {{#time: jS F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| 2 = {{#time: jnd F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| 22 = {{#time: jnd F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| 3 = {{#time: jrd F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| 23 = {{#time: jrd F Y | {{{date}}} - {{{days|1}}} days }} |
|||
| #default = {{#time: jth F Y | {{{date}}} - {{{days|1}}} days }} |
|||
}} |
|||
}} |
}} |
||
| Please specify a valid date and operation (add or subtract). |
|||
}} |
}} |
||
Latest revision as of 17:23, 17 December 2024
Usage
[edit source]The `Date-calc` template performs date arithmetic (addition or subtraction) using days, weeks, and months. It is useful for calculating dates relative to a given date.
Parameters
[edit source]- date – The starting date in any valid format recognizable by the `#time` parser function (e.g., `1 April 2024`, `27 December 2025`).
Required
[edit source]- operation – Specifies whether to add or subtract time. Valid values are:
* add * subtract
- days – The number of days to add or subtract. Defaults to 0 if not provided.
- weeks – The number of weeks to add or subtract. Defaults to 0 if not provided.
- months – The number of months to add or subtract. Defaults to 0 if not provided.
Output
[edit source]The template outputs the resulting date in the format DD Month YYYY (e.g., 15 January 2024).
Examples
[edit source]Adding Time
[edit source]- To add 2 months and 10 days to 1 January 2024:
{{Date-calc|date=1 January 2024|operation=add|months=2|days=10}}
Output: 11 March 2024
- To add 3 weeks to today's date:
{{Date-calc|date={{TODAY}}|operation=add|weeks=3}}
Output: (depends on today's date)
Subtracting Time
[edit source]- To subtract 1 month and 2 weeks from 17 December 2024:
{{Date-calc|date=17 December 2024|operation=subtract|months=1|weeks=2}}
Output: 3 November 2024
- To subtract 15 days from 15 March 2024:
{{Date-calc|date=15 March 2024|operation=subtract|days=15}}
Output: 29 February 2024
Error Handling
[edit source]If required parameters are missing:
{{Date-calc|date=|operation=add}}
Output: Please specify a valid date and operation (add or subtract).
Notes
[edit source]- The template uses the `#time` parser function, which supports various date formats.
- The `days`, `weeks`, and `months` parameters can be used together or separately.
- If all time parameters (days, weeks, and months) are omitted, no calculation is performed, and the input date is returned as-is.
Please specify a valid date and operation (add or subtract).