1``date`` 2======== 3 4.. versionadded:: 1.6 5 The date function has been added in Twig 1.6. 6 7.. versionadded:: 1.6.1 8 The default timezone support has been added in Twig 1.6.1. 9 10Converts an argument to a date to allow date comparison: 11 12.. code-block:: jinja 13 14 {% if date(user.created_at) < date('-2days') %} 15 {# do something #} 16 {% endif %} 17 18The argument must be in one of PHP’s supported `date and time formats`_. 19 20You can pass a timezone as the second argument: 21 22.. code-block:: jinja 23 24 {% if date(user.created_at) < date('-2days', 'Europe/Paris') %} 25 {# do something #} 26 {% endif %} 27 28If no argument is passed, the function returns the current date: 29 30.. code-block:: jinja 31 32 {% if date(user.created_at) < date() %} 33 {# always! #} 34 {% endif %} 35 36.. note:: 37 38 You can set the default timezone globally by calling ``setTimezone()`` on 39 the ``core`` extension instance: 40 41 .. code-block:: php 42 43 $twig = new \Twig\Environment($loader); 44 $twig->getExtension('\Twig\Extension\CoreExtension')->setTimezone('Europe/Paris'); 45 46 // before Twig 1.26 47 $twig->getExtension('core')->setTimezone('Europe/Paris'); 48 49Arguments 50--------- 51 52* ``date``: The date 53* ``timezone``: The timezone 54 55.. _`date and time formats`: https://secure.php.net/manual/en/datetime.formats.php 56