Define format for publish_date

I loop through posts and load publish_date to show it on a page. It shows as Y-m-d H:i:s and I am wondering why it is not showing as set in the general settings (as it is with <Date />). <Date /> can be tweaked with different additional parameters (as for example <Date format="d.m.Y" />) but they don’t seem to be working with publish_date. Why? Or is there anything else I need to set or define for showing publish_date in an other way?

Hi Daniel! You can wrap <Field publish_date /> in the date or format tag to format it: <Date format="d.m.Y"><Field publish_date /></Date> and <Format date="d.m.Y"><Field publish_date /></Format> both work.

2 Likes

Thank you Julia for helping me out. I tried some combinations that were kind of like the same but did not work in the end. Maybe that would be a nice addition to the documentation for others like me.

I think of adding to the end of the “Date”-Page something like:

–––
Format loaded dates
It is possible to format loaded dates (for example publish_date) in the same way as described. Just wrap the query in the Date selector and add formatting to it:

<Date format="d.m.Y"><Field publish_date /></Date>
–––

Just an idea. As I said it is kind of described already but the combination didn’t work out. I thougt the formatting needs to be added to the field like <Field publish_date format="d.m.Y"/> but that is not correct as I learnt now. But maybe I am the only one not getting it in the first point :wink:

2 Likes

Hi Daniel,

Thank you for the suggestion - I added some information about date format and field value.

There is actually a shortcut for the Field tag, but the attribute is called date_format.

<Field publish_date date_format="d.m.Y" />

It had to use a different attribute instead of just format, because there are other formatting functions like format=lowercase (not documented yet).

1 Like

Thank you, Eliot! That is perfect and provides all the information needed.

1 Like