5 The date function has been added in Twig 1.6.
7 .. versionadded:: 1.6.1
8 The default timezone support has been added in Twig 1.6.1.
10 Converts an argument to a date to allow date comparison:
14 {% if date(user.created_at) < date('-2days') %}
18 The argument must be in one of PHP’s supported `date and time formats`_.
20 You can pass a timezone as the second argument:
24 {% if date(user.created_at) < date('-2days', 'Europe/Paris') %}
28 If no argument is passed, the function returns the current date:
32 {% if date(user.created_at) < date() %}
38 You can set the default timezone globally by calling ``setTimezone()`` on
39 the ``core`` extension instance:
43 $twig = new Twig_Environment($loader);
44 $twig->getExtension('Twig_Extension_Core')->setTimezone('Europe/Paris');
47 $twig->getExtension('core')->setTimezone('Europe/Paris');
53 * ``timezone``: The timezone
55 .. _`date and time formats`: https://secure.php.net/manual/en/datetime.formats.php