Date header does not seem to be taken into consideration

I’m trying to set a post date in a site using casper theme.
In the casper theme code, I can see that the date is parsed using:

{{|date('F d. Y.') }}

So I assumed that setting the header of my post as the following would display the appropriate date in the post page. Instead, it’s displaying today’s date. So it seems it’s taking as date when I last modified the post’s markdown file.

template: item
title: Some blogpost
date: 2022-01-06

Please note that I have the appropriate date format in my config/system.yaml file:

    default: Y-m-d
    short: Y-m-d
    long: Y-m-d_H:i

Anyone has an idea why the date is not displaying as it should?

In a custom theme, I used the following twig expression and it’s behaving as expected:

{{|date(system.pages.dateformat.short) }}

I would really like to avoid having to customize the casper theme to achieve this behaviour which seem to me like it would be the expected one.

Or did I misunderstand something?

@squeak, According the documentation about the date frontmatter it says:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/ ), then the American m/d/y is assumed; whereas if the separator is a dash (- ) or a dot (. ), then the European d.m.y format is assumed.

Try one of the supported formats. Eg.:

template: item
title: Some blogpost
date: 06-01-2022

Hello @pamtbaau, thanks a lot for your answer.
Indeed trying the format you propose does work. I’ll consider using this workaround if there’s no alternative.

However I would expect that filling the system config dateformat the way I did, would allow me to use the date format it describes. It’s a bit confusing to me to be able to specify a default date format, but that the date I input is not used if I don’t use the standard grav date format.

It’s even stranger because the Y-m-d formatted date is recognized (which is not the case if I don’t set the dateformat.default config, in which case an error is thrown). It is recognized, but not used.
I’m a bit perplex with this issue. I think I’ll dig more into grav issue tracker and maybe post an issue there.

After a bit more investigations.
The following header does work:

template: item
title: Some blogpost
date: "2022-01-06"

Note the quotes around the date.
All this is strange :wink:

For the record, I created an issue in the grav issue tracker to report this. Let’s see how it goes there.

@squeak, When using the following format in system.yaml:

    default: U

And the following date in the header of the page:

date: 2024-01-01   # without quotes

Will output January 01. 2024. using {{|date('F d. Y.') }}


  • When using a date without quotes, the date is seen as unixepoch internally. Hence the U as format.
1 Like

Thanks a lot @pamtbaau for posting about this solution :slight_smile:

I couln’t test it now with casper because I stopped using it and decided to build a custom theme. In my custom theme, I use:|date(system.pages.dateformat.short)

in the template. And set config/system.yaml to:

    default: Y-m-d

Then in pages I set dates with the following format:

date: 2022-01-06

It all works as I’d expect it to. And outputs 2022-01-06 in pages.