Print UK Date Format for Post Date
When making this site, we wanted to show the date (above the title) in the British format by putting the day before the month. Controversial, I know. This also means including the date ordinal/suffix after the day, e.g.
If you were writting this format in PHP it would look like this:
With the ‘S’ standing for:
English ordinal suffix for the day of the month, 2 characters
This is what we were trying to recreate when using Hugo, but it’s a bit tricky as Hugo is built on Go’s time formatting - which doesn’t have support for this suffix style. Because of this, we have to do the logic ourselves by working out the day and based on if it’s in certain lists (slices), show the correct text.
Which then prints the date to the page like this:
This code is based on the example in the Hugo docs.
Site illustrations (of Hugo the rabbit) drawn by Carina Roberts.