1``format_datetime``
2===================
3
4.. versionadded:: 2.12
5
6    The ``format_datetime`` filter was added in Twig 2.12.
7
8The ``format_datetime`` filter formats a date time:
9
10.. code-block:: twig
11
12    {# Aug 7, 2019, 11:39:12 PM #}
13    {{ '2019-08-07 23:39:12'|format_datetime() }}
14
15You can tweak the output for the date part and the time part:
16
17.. code-block:: twig
18
19    {# 23:39 #}
20    {{ '2019-08-07 23:39:12'|format_datetime('none', 'short', locale='fr') }}
21
22    {# 07/08/2019 #}
23    {{ '2019-08-07 23:39:12'|format_datetime('short', 'none', locale='fr') }}
24
25    {# mercredi 7 août 2019 23:39:12 UTC #}
26    {{ '2019-08-07 23:39:12'|format_datetime('full', 'full', locale='fr') }}
27
28Supported values are: ``none``, ``short``, ``medium``, ``long``, and ``full``.
29
30For greater flexiblity, you can even define your own pattern (see the `ICU user
31guide
32<https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax>`_
33for supported patterns).
34
35.. code-block:: twig
36
37    {# 11 oclock PM, GMT #}
38    {{ '2019-08-07 23:39:12'|format_datetime(pattern="hh 'oclock' a, zzzz") }}
39
40By default, the filter uses the current locale. You can pass it explicitly:
41
42.. code-block:: twig
43
44    {# 7 août 2019 23:39:12 #}
45    {{ '2019-08-07 23:39:12'|format_datetime(locale='fr') }}
46
47.. note::
48
49    The ``format_datetime`` filter is part of the ``IntlExtension`` which is not
50    installed by default. Install it first:
51
52    .. code-block:: bash
53
54        $ composer require twig/intl-extra
55
56    Then, on Symfony projects, install the ``twig/extra-bundle``:
57
58    .. code-block:: bash
59
60        $ composer require twig/extra-bundle
61
62    Otherwise, add the extension explicitly on the Twig environment::
63
64        use Twig\Extra\Intl\IntlExtension;
65
66        $twig = new \Twig\Environment(...);
67        $twig->addExtension(new IntlExtension());
68
69Arguments
70---------
71
72* ``locale``: The locale
73* ``dateFormat``: The date format
74* ``timeFormat``: The time format
75* ``pattern``: A date time pattern
76