Use a predefined PHP date format when using the Twig date filter
Published on 2019-08-18 • Modified on 2019-08-18
This is another example where the constant
Twig function can be helpful. In this case we get the \DateTime::ATOM
PHP constant to pass the value to the date
filter. I am using it when generating the dates values of the Atom XML feeds.
{{ 'now'|date(constant('\DateTime::ATOM')) }}
Code execution output:
2025-01-18T17:42:46+01:00
More on Stackoverflow Read the doc Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉