{daterange:start_timestamp:end_timestamp:year_format:hour_delimiter}

Description

Formats a start and end timestamp as a compact date range, mainly for event calendars. It collapses the parts the two dates share: a range on a single day prints just that date, a range inside one year prints the year only once at the end, and a range across two years prints both years. If a timestamp carries a time of day other than midnight (or 23:59 at the end), that time is shown after the date. The output uses narrow non-breaking spaces after the day and month numbers and an en-dash between the two dates, so it stays on one line and reads as a typographic date range rather than plain ASCII.

Parameters

start_timestamp required default (empty)

Unix timestamp of the start date, usually fed from an item start-date field. A time of 0:00 is treated as all-day and no time is shown.

end_timestamp required default (empty)

Unix timestamp of the end date, usually an item expiry-date field. The output collapses components shared with the start: a same-day range prints one date, a same-year range prints the year only once. An end time of 0:00 or 23:59 is treated as all-day and hidden.

year_format optional default Y

PHP date() year format applied to the printed year: Y gives 2008, y gives 08, an empty value prints no year.

hour_delimiter optional default a single space

Separator placed between the date and the time of day. A comma-space ', ' gives '15. 9. 2024, 18:30'.

Examples

virtual{daterange:1230073200:1230073200}
Expected(24. 12. 2008)
Actual24. 12. 2008
Start and end fall on the same day with no time of day set, so {daterange} prints just that one date. The dots are followed by narrow non-breaking spaces in the live output.
virtual{daterange:1717192800:1717365600}
Expected(1. 6. - 3. 6. 2024)
Actual1. 6.  – 3. 6. 2024
Start and end are in the same year, so the year is printed only once, at the end. The two days are joined by spaced en-dashes in the live output.
virtual{daterange:1703977200:1704150000}
Expected(31. 12. 2023 - 2. 1. 2024)
Actual31. 12. 2023 – 2. 1. 2024
When start and end are in different years, both years are printed in full.
virtual{daterange:1230073200:1230418800:y}
Expected(24. 12. - 28. 12. 08)
Actual24. 12.  – 28. 12. 08
The third parameter sets the year format: Y for 2008 (default), y for 08, or empty for no year.
virtual{daterange:1726417800:1726426800}
Expected(15. 9. 2024 18:30-21:00)
Actual15. 9. 2024 18:30–21:00
When the timestamps carry a time of day, that time is shown after the date. A start and end time on the same day print as start-end. A 0:00 start or a 0:00/23:59 end is treated as all-day and the time is hidden.
virtual{daterange:1726417800:1726417800:Y:, }
Expected(15. 9. 2024, 18:30)
Actual15. 9. 2024, 18:30
The fourth parameter is the delimiter between the date and the time. It defaults to a single space; pass ', ' to put a comma between them.
virtual{daterange:{start_date......}:{expiry_date.....}}
Expected(e.g. 24. 12. - 28. 12. 2008)
Actual1. 1. 1970 1:00 – 31. 12. 2037
The real-world pattern: feed an item's start-date and expiry-date fields. Output depends on the item, so this example is illustrative only.