Template:Weekday before date
Usage
[edit]{{Weekday before date|Y|M|D|W|S}} uses the optional date format string S (defaults to "F d, Y") to return the date of the first W (=Sunday, Monday, ..., Saturday) before the specified date with year Y, month M (spelled out), and day of month D.
Examples
[edit]The first Sunday before November 18, 2026 is given by "{{Weekday before date|2026|November|18|Sunday}}" as "November 15, 2026".
In the following table, 31 October 2010 is a Sunday.
| Syntax | What it looks like | Notes |
|---|---|---|
{{Weekday before date|2010|October|31|Monday|d F Y}} |
25 October 2010 | |
{{Weekday before date|2010|October|31|Tuesday|d F Y}} |
26 October 2010 | |
{{Weekday before date|2010|October|31|Wednesday|d F Y}} |
27 October 2010 | |
{{Weekday before date|2010|October|31|Thursday|Y-m-d}} |
2010-10-28 | |
{{Weekday before date|2010|October|31|Friday|Y-m-d}} |
2010-10-29 | |
{{Weekday before date|2010|October|31|Saturday|d F Y}} |
30 October 2010 | |
{{Weekday before date|2010|October|31|Sunday|d F Y}} |
24 October 2010 | When a starting date falls on the specified weekday, the resulting date will be one week earlier. |
{{Weekday before date|2010|10|31|Thursday|d F Y}} |
Error: Invalid time. | Numeric month results in error |
See also
[edit]Returns the date of the first specified weekday occurring before a given date.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Year | 1 | The year of the starting date (e.g., 2026).
| Number | required |
| Month | 2 | The month of the starting date (spelled out, e.g., April).
| String | required |
| Day | 3 | The day of the month of the starting date.
| Number | required |
| Weekday | 4 | The target day of the week to find before the date (e.g., Thursday, Sunday).
| String | required |
| Date format | 5 | An optional PHP-style date format string for the output (defaults to "F d, Y").
| String | optional |