Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Templating with Twig!
You have completed Templating with Twig!
Date can be used both as a filter and as a function. Because twig compiles to PHP, and Twig's date function returns a valid dateTime object, we can use PHP method calls on our date.
The date filter formats a date to a given format:
{{ post.published_at|date("m/d/Y") }}
The date function converts an argument to a date to allow date comparison:
{% if date(user.created_at) < date('-2days') %}
{# do something #}
{% endif %}
Both the filter and the function may accept a timezone.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up