What do I put into my config.yaml file, in order to change the date on my posts to ISO 8601

I’ve found heaps of seemingly outdated posts about this, and I can’t find anything of use in the Hugo docs. What am I meant to actually type?

Could you please be more precise what you mean with:

change the date on my posts

it’s a big difference if

  • just format of new posts?
    or
  • migrate your posts?

also the variant ISO 8601? (exact format you need

an example could also help to catch the audience

  • whats your config
  • where are your dates
1 Like

Both?

Doesn’t have to be ISO 8601 specifically, I just don’t want the American format, and ISO 8601 is a standard.

I encourage you to take a squiz at the recent commit history. I feel like I’ve tried everything.

hugo.toml

[params]
  dateFormat = "2006-01-02"

Then in your templates.

{{ .Date.Format site.Params.dateFormat }}
1 Like

If you wish to localize (format + translate) a date, use the time.Format function with a localization token:

{{ .Date | time.Format ":date_medium" }}

https://gohugo.io/functions/time/format/#localization

1 Like

Short Answer:

read your Theme Docs and examples → WonderMod → PaperMod → Installation · adityatelange/hugo-PaperMod Wiki · GitHub

params:
    dateFormat: "MYDATE  2006-01-02 MYDATE"

will be picked automatically from your theme

DOSBox

MYDATE 2024-03-19 MYDATE · 6 min · 1192 words · mindlux | Suggest Changes

Last updated on MYDATE 2024-03-26 MYDATE

<tl>;<tr>

The date is an attribute in your Frontmatter of all pages. It is set when you create a new page using hugo new content

It will be taken from `archetypes\default.md and is defined as:

---
date: {{ .Date }}
---

When generating the site your Theme formats this value using

  • \themes\WonderMod\layouts\partials\post_lastmod.html
  • \themes\WonderMod\layouts\partials\post_meta.html

there’s a code inside that formats according to the mentioned config option from the top.

{{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.Date) (.Date | time.Format (default "January 2, 2006" site.Params.DateFormat)))) }}
1 Like

But when I change the date in these files (as you could see now):

Such as you listed here:

Nothing changes.

P.S. Thank you for your time, that looked like it took an amount of effort to go through.

@irkode already answered your question.

If I clone your site, then add this to the site config under the params key…

dateFormat: 2 January 2006

…this is what I see when I build your site:

image

1 Like

Sry for the confusion

The code refernences where just explainatory.

Leave the theme alone and configure it using the value in your config file.

Updated the solution ro make it clearer

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.