I am setting up Google Tag Manager's Data Layer and I have a .twig as my header file. I need to produce the date and time of the post in ISO 8601 format.

"datePublished": "{{post.date}}"

This produces the date but not in the right format. How do I format the date/Time to this standard?

Thank you.

  • How are you using Twig? Searching for "twig format date iso 8601" suggests using |date("c") as twig filter – kero Oct 12 '18 at 8:34

Thanks Kero, That was correct.

Here is the final code that works

"datePublished": "{{post.date|date('c')}}",

Here is the link

How to format a datetime object to ISO 8601 in Twig

Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.