# Changing date format in front matter

**URL:** <https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305>\
**Category:** support\
**Created:** [July 16, 2023, 9:46am UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305 "2023-07-16T09:46:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [July 16, 2023, 9:46am UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/1 "2023-07-16T09:46:35Z")

</div>

Is there a simple way to convert dates from a format like `14 Jan 2006` to `2006-01-14`?

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [July 16, 2023, 11:04am UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/2 "2023-07-16T11:04:55Z")

</div>

You can convert a string to a date via `time.AsTime`, but I don’t understand your use case, are you using custom date parameters other than `Date`, `PublishDate` or other built-in date’s vars in front matter?

```go
{{ ("14 Jan 2006" | time.AsTime).Format "2006-01-02" }}

```

---

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [July 16, 2023, 11:54am UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/3 "2023-07-16T11:54:48Z")

</div>

I mean in my markdown files, not in templates.

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [July 16, 2023, 12:13pm UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/4 "2023-07-16T12:13:26Z")

</div>

You can use the [archetype](https://gohugo.io/content-management/archetypes/) for new content.

```markdown
---
date: {{ (.Date | time.AsTime).Format "2006-01-02" }}
---

```

---

<div class="post-metadata">

**Author:** ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)\
**Post date:** [July 16, 2023, 1:20pm UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/5 "2023-07-16T13:20:14Z")

</div>

I personally don’t like starting files with `hugo new content blabla", but more importantly frontmatters are static and if you’re putting dates on your site, then create dates don’t really matter for people, unlike publishing date or last modification dates, which don’t / can’t go in the frontmatter. Because it’s not adding any information, I think it’s more flexible to just use the date formatting functions wherever you need in your templates/partials.

---

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [July 16, 2023, 1:51pm UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/6 "2023-07-16T13:51:08Z")

</div>

What about existing content?

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [July 16, 2023, 2:12pm UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/7 "2023-07-16T14:12:33Z")

</div>

I think you’ve to write a script to replace the date with your new format for previous contents, but the date format in contents doesn’t matter to me, it makes more sense that to format it in templates.

---

<div class="post-metadata">

**Author:** ![Arif](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/arif/32/20931_2.png) [@Arif](https://discourse.gohugo.io/u/Arif)\
**Post date:** [July 16, 2023, 8:23pm UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/8 "2023-07-16T20:23:52Z")

</div>

Did everything manually (tedious but worked).

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [July 18, 2023, 8:24pm UTC](https://discourse.gohugo.io/t/changing-date-format-in-front-matter/45305/9 "2023-07-18T20:24:20Z")

</div>

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