date.rst 730B

12345678910111213141516171819202122232425262728293031323334
  1. ``date``
  2. ========
  3. .. versionadded:: 1.6
  4. The date function has been added in Twig 1.6.
  5. Converts an argument to a date to allow date comparison:
  6. .. code-block:: jinja
  7. {% if date(user.created_at) < date('+2days') %}
  8. {# do something #}
  9. {% endif %}
  10. The argument must be in a format supported by the `date`_ function.
  11. You can pass a timezone as the second argument:
  12. .. code-block:: jinja
  13. {% if date(user.created_at) < date('+2days', 'Europe/Paris') %}
  14. {# do something #}
  15. {% endif %}
  16. If no argument is passed, the function returns the current date:
  17. .. code-block:: jinja
  18. {% if date(user.created_at) < date() %}
  19. {# always! #}
  20. {% endif %}
  21. .. _`date`: http://www.php.net/date