Date/Time format in config.toml

Hi,

I could not figure out if and how it’s possible to set a custom time format for articles in the config file.
So I would like to have the .Date Variable to the German “DD.MM.YYYY” in the rendered output (Frontmatter is like YYYY-MM-DD).

In some template I found
{{ if .Site.Params.strings.date_format }}{{ .Date.Format .Site.Params.strings.date_format }}{{ else }}{{ .Date.Format "Mon, 2. Jan. 2006" }}{{ end }}

so I put this
[params] date_format = "Mon, 2. Jan. 2006"
in my config.toml but it doesn’t work … any hint to the right direction appreciated.

sorry, internal search made me write this question.

Google site search pointed me to this https://discuss.gohugo.io/t/parsing-dates-in-templates/603/10 and it does do something now:

Config.toml:
[params] DateForm = "30.12.2006"

and in the template:
{{ .Date.Format .Site.Params.DateForm }}

but date = "2011-04-16" in Frontmatter will give 120.416.2011 as a result :astonished:

I haven’t tested it, but suppose you need to use:

[params]
    DateForm = "2.1.2006"

The reason for this format originates from Go, the programming language that Hugo uses. There’s probably more information about the different ways to format Hugo dates in the docs and on the forum.

1 Like

Thanks - you saved my day!
Indeed it is this one specified date that MUST be used for a reference.