Hi,
There’s a way to convert a month number to string?
For example: 01 to “January”, 02 to “February”, etc…
Bye and thanks
Hi,
There’s a way to convert a month number to string?
For example: 01 to “January”, 02 to “February”, etc…
Bye and thanks
See
Yes, I checked this page but don’t works.
I used:
{{ dateFormat "Jan" "01" }}
But hugo fails to start showing this message:
executing "main" at <dateFormat "Jan" "01">: error calling dateFormat: unable to parse date: 01
You need to use a proper date format as input and another one as output. Then in your templates you can render the month with {{ .Date.Month }}
.
If you want to map arbitrary numbers then you should create your own dictionary and range over it as you wish: https://gohugo.io/functions/dict/#readout
The problem is that dateFormat wants an ISO date (e.g. “2020-07-19”), and won’t work with an isolated month number. The following line will convert an arbitrary integer in $monthindex into a full month name (e.g. 1 to “January”, 2 to “February”, etc.):
{{ dateFormat "January" (printf "2001-%02d-01" $monthindex) }}