Lukas Lukac
Lukas Lukac

Reputation: 8376

Symfony, twig, date

Easy question but i could find answer here: http://twig.sensiolabs.org/doc/filters/date.html

I have this: user.birthday|date("Y\m\d")

but the output is to example: 19930224

and i want to separate it buy "/" to example like: 1993/02/24

Any idea? Thx!

Upvotes: 1

Views: 971

Answers (2)

cheesemacfly
cheesemacfly

Reputation: 11762

In the date() function, you need to escape \ with a second one as \\.

And as said in the twig documentation:

To escape words and characters in the date format use \\ in front of each character

So you need to escape it as following in your twig template:

{{ user.birthday|date('Y\\\\m\\\\d') }}

Upvotes: 0

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70466

You cannot use backslash \ because it is used for escaping characters. You can use / instead.

Upvotes: 1

Related Questions