Date formatting with Twig

Hi

I have the following Twig statement
{% set event = looper.item %}
{{ event.event_date }}

which returns 20250310 from an ACF field which looks to be correct for 10th March 2025

following this post Format Looper Twig Date

I created this
{% set event = looper.item %}
{{ event.event_date | date(‘F j’)}} @ {{ event.event_time | date(‘g:i a’)}}

to display the date and time in a more readable format but it is returning August 23

i am not certain how to use the other option in the post
{{ looper.field({“key”:“time”, “format”: “F j, Y”, “type”: “date”}) }}

Hello,

Thank you for the inquiry.

It returns August 23 because Twig interprets 20250310 as a timestamp or datetime, not 10th March 2025. You may need to convert the event.event_date to 2025-03-10 first, before converting it to the actual date format that you prefer. Please try this template:

{% set date = event.event_date|slice(0, 4) ~ "-" ~ event.event_date|slice(4, 2) ~ "-" ~ event.event_date|slice(6, 2) %}
{{ date | date("jS F Y") }}

Let us know the result.

Best regards.

i’m getting this error

See our troubleshooting guide about “Unable to create the cache directory”. You can also turn off the “Cache” in the Twig Theme Options. Have a great day.

Thanks for your help
For others on the same journey i ended up using the following with great directions from the ThemeCo support staff

{% set event = looper.item %}
{% set date = event.event_date|slice(0, 4) ~ “-” ~ event.event_date|slice(4, 2) ~ “-” ~ event.event_date|slice(6, 2) %}
{{ date | date(“jS F Y”) }} @ {{ event.event_time | date(‘g:i a’)}}

pulling data from a Dynamic Content looper provider of {{dc:acf:post_field field=“events”}} which was returning an array from a bidirectional relationship field created by ACFpro

Hey @The_Capture_Factory,

We’re glad that you’re able to figure it out!

Cheers!