Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

How to change the format of dates in a page

Solved by pamtbaau View solution

Started by Salvis 4 years ago · 3 replies · 1730 views
4 years ago

I can not find how to set the correct Date format for published pages / blog items.

I want to set date first - followed by month...

I have done all I could to set the Default Date settings both in app and after in settings.yml , nothing changed...

Then I went into particular Page settings - there is an option to set Date.... but there is a popup javascript calendar - which it seems support only 1 date format - May 22, 2022; No way I can force it to set & display 22 May 2022

As a last resort - I was trying to modify date format in .md files themselves - but no luck.... whatever I write there - it interprets in American manner....

so I need 22 May 2022 , instead of May 22 2022 ....

Also - I would be happy about 24h clock format, I never got it....

I am trying to use Bootstrap 4 theme, which I yesterday downloded, I am 2 day on this Grav....

p.s. as a sidenote - could you change the Avatars, so it won't show the Z sign on my avatar?! Lately Z symbol stands for Russian invasion in Ukraine, it is forbidden in several countries in Europe now...

last edited 05/22/22 by Salvis
4 years ago Solution

@zambala, The date format is often set in the template.

Quark:
In Quark /templates/partials/blog/date.html.blog the date output is formatted as follows:

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

Note, the |date filter uses the dateformat as set in system.yaml.

The default format that comes with Grav in system.yaml is:

YAML
pages:
  dateformat:
    default:                                     # The default date format Grav expects in the `date: ` field
    short: 'jS M Y'                              # Short date format
    long: 'F jS \a\t g:ia'                       # Long date format

Which will display the date as 11th Aug 2017. See PHP DateTime formats.

Bootstrap4:
Bootstrap 4 uses another way to output the dates: See /templates/partials/blog_item.html.twig line 23

TWIG
{{ page.date|date("F j, Y, g:i a") }}

As you can see, the output format is hardcoded as August 11, 2017, 2:55 pm. No matter what you set, the display of the date will remain the same.

Solution:
Create a child theme of Bootstrap 4 and change template blog_item.html.twig to your liking.

Avatar:
You can provide your own in your profile.

👍 1
4 years ago

Thanks, the Item template date seems working...

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
3 92 2 hours ago
Support · by Anna, 3 days ago
2 94 23 hours ago
Support · by Justin Young, 1 day ago
1 62 24 hours ago
Support · by Duc , 1 week ago
2 98 6 days ago
Support · by Colin Hume, 1 week ago
2 91 6 days ago