# `date`
New in version 1.6: The date function has been added in Twig 1.6.
New in version 1.6.1: The default timezone support has been added in Twig 1.6.1.
Converts an argument to a date to allow date comparison:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre>{% if date(user.created_at) < date('-2days') %}
{# do something #}
{% endif %}
</pre></div></td></tr></table>
The argument must be in one of PHP鈥檚 supported [date and time formats](http://php.net/manual/en/datetime.formats.php) [http://php.net/manual/en/datetime.formats.php].
You can pass a timezone as the second argument:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre>{% if date(user.created_at) < date('-2days', 'Europe/Paris') %}
{# do something #}
{% endif %}
</pre></div></td></tr></table>
If no argument is passed, the function returns the current date:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre>{% if date(user.created_at) < date() %}
{# always! #}
{% endif %}
</pre></div></td></tr></table>
Note
You can set the default timezone globally by calling `setTimezone()` onthe `core` extension instance:
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre>$twig = new Twig_Environment($loader);
$twig->getExtension('core')->setTimezone('Europe/Paris');
</pre></div></td></tr></table>
### Arguments
- `date`: The date
- `timezone`: The timezone
- Twig
- Introduction
- Installation
- Twig for Template Designers
- Twig for Developers
- Extending Twig
- Twig Internals
- Deprecated Features
- Recipes
- Coding Standards
- Tags
- autoescape
- block
- do
- embed
- extends
- filter
- flush
- for
- from
- if
- import
- include
- macro
- sandbox
- set
- spaceless
- use
- verbatim
- Filters
- abs
- batch
- capitalize
- convert_encoding
- date
- date_modify
- default
- escape
- first
- format
- join
- json_encode
- keys
- last
- length
- lower
- merge
- nl2br
- number_format
- raw
- replace
- reverse
- round
- slice
- sort
- split
- striptags
- title
- trim
- upper
- url_encode
- Functions
- attribute
- block
- constant
- cycle
- date
- dump
- include
- max
- min
- parent
- random
- range
- source
- template_from_string
- Tests
- constant
- defined
- divisible by
- empty
- even
- iterable
- null
- odd
- same as