]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/doc/functions/date.rst
twig implementation
[github/wallabag/wallabag.git] / vendor / twig / twig / doc / functions / date.rst
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
10 Converts 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
18 The argument must be in a format supported by the `date`_ function.
19
20 You 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
28 If 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('core')->setTimezone('Europe/Paris');
45
46 Arguments
47 ---------
48
49 * ``date``: The date
50 * ``timezone``: The timezone
51
52 .. _`date`: http://www.php.net/date