I use a branch to indicate a row in the table if the date associated with this row is less than 30 days.
The Twig documentation states that to compare two date objects, you must first convert the object to a date, and then do the comparison in this way:
{% if date(yourDate) < date(-'30days') %} ... {% endif %}
However, it does not indicate how to pass the date format for the left side of the comparison, I understand that the Twig date function is a kind of wrapper for the PHP date.
In PHP, I usually called:
$myDate = \DateTime::createFromFormat("m/d/Y", $myDate);
but in Twig, there seems to be no way to specify the original date format to convert it to another format, or at least to the documentation.
Here is what I tried:
{% if date(d.LastDate) > date('-30days') %}...{% endif %}
{% if d.LastDate | format("Ymd") > date('-30days') %}...{% endif %}
{% if date("m/d/Y", d.LastEmailSentDate) > date('-30days') %}...{% endif %}
These conditions and their variants return the following exception in Symfony2:
An exception has been thrown during the rendering of a template ("DateTimeZone::__construct(): Unknown or bad timezone (---)")
My controller returns a date in the format: m/d/Y , and I just want to mark this line if this date is less than 30 days.