Mark Cibor
Mark Cibor

Reputation: 2807

How can I convert a date to a UNIX timestamp with Twig?

I need to convert a date to a UNIX timestamp in a Twig template:

 <li>{{ user.expired }}</li>

Is there a function in Twig to do it?

Upvotes: 20

Views: 32712

Answers (1)

Florian Klein
Florian Klein

Reputation: 8915

There is the built-in date filter in Twig. You can pass any strtotime-compatible argument.

 <li>{{ user.expired | date('U') }}</li>

U is the pattern that will display the unix timestamp.

Upvotes: 68

Related Questions