Date Formatting of Params

I noticed that this would change how a date is presented from a template:

{{ .Date.Format "Mon, Jan 2, 2006" }}

And thought that I could use the same on a Param but it is not producing any result:

{{ .Params.approvalDate.Format "Mon, Jan 2, 2006" }}

Is there any way to treat this Param as a true date?

It’s probably just your formatting of the date in the frontmatter. The date value has to be very specifically formatted for Hugo to realize it’s a date and not something else (like a string). What type of frontmatter are you using? If it’s toml, the date needs to be in ISO 8601 full zulu form like 2006-05-27T07:32:00Z If it’s another frontmatter type, I’m not sure, but google probably can help you there.

I believe Json and YAML don't have native date types.

So if YAML doesn’t have a native date type there’s no way to use .Params.someDate.Format to display a date in a desired format?

You could use the dateFormat template function.

3 Likes

Perfect, thanks!