Date and time
This utility provides date formatting functions. It was originally written by Allen Chang.
XML
To format a date, the entries in your data source should contain a node with a date field, for example:
<example-datasource>
<entry id="152">
...
<published-on iso="2025-08-22T17:45:00+02:00" timestamp="1755877500" time="17:45" weekday="5" offset="+0200">2025-08-22</published-on>
...
</entry>
</example-datasource>
Call template
Add the template for date formatting to your main template, eg. <xsl:import href="utility-date-time.xsl"/>
.
The named template format-date
accepts two parameters:
date
- [required] ISO date (e.g.2025-09-15
)format
- [optional] format string.
If you are inside a matching template for an entry, call the utility template like this:
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="published-on" />
<xsl:with-param name="format" select="'M D, Y'" />
</xsl:call-template>
Format options
Y
- year in 4 digits e.g. 1981, 1992, 2025y
- year in 2 digits e.g. 81, 92, 25M
- month as a full word e.g. January, March, Septemberm
- month in 3 letters e.g. Jan, Mar, SepN
- month in digits without leading zeron
- month in digits with leading zeroD
- day with suffix and no leading zero e.g. 1st, 23rdd
- day in digits with leading zero e.g. 01, 09, 12, 25x
- day in digits with no leading zero e.g. 1, 9, 12, 25T
- time in 24-hours e.g. 18:30t
- time in 12-hours e.g. 6:30pmW
- weekday as a full word e.g. Monday, Tuesdayw
- weekday in 3 letters e.g. Mon, Tue, WedZ
- timezone (offset)
Possible errors
If “NaN” is displayed instead of the expected date, this usually has one of two causes:
- The entry does not contain an element with a date.
- There is a typing error for the node with the name that contains the date.