title: in Twig how to compare if date is within X days?
body: <p>I'm using twig to flag a row in a table, if the date associated with that row is less than 30 days old. </p>
  
  <p>Twig's documentation states that to compare two date objects, you have to convert the object to date first, and then make a comparison this way:</p>
  
  <p><code>{% if date(yourDate) &lt; date(-'30days') %} ... {% endif %}</code></p>
  
  <p>However, it doesn't specify how to pass the date format for the left side of the comparison, I understand that Twig's date function is some sort of a wrapper for PHP's date. </p>
  
  <p>In PHP I would usually call:</p>
  
  <p><code>$myDate = \DateTime::createFromFormat("m/d/Y", $myDate);</code></p>
  
  <p>but in Twig apparently there's no way to specify the original date's format in order to convert it to another format, or at least it's not in the documentation. </p>
  
  <p>This is what I've tried:</p>
  
  <p><code>{% if date(d.LastDate) &gt; date('-30days') %}...{% endif %}</code></p>
  
  <p><code>{% if d.LastDate | format("Y-m-d") &gt; date('-30days') %}...{% endif %}</code></p>
  
  <p><code>{% if date("m/d/Y", d.LastEmailSentDate) &gt; date('-30days') %}...{% endif %}</code></p>
  
  <p>Those conditions and their variations return the following exception in Symfony2:</p>
  
  <pre><code> An exception has been thrown during the rendering of a template 
  ("DateTimeZone::__construct(): Unknown or bad timezone (---)")
  </code></pre>
  
  <p>My controller is returning a date in the format: <code>m/d/Y</code> and I just want to flag that row if that date is less than 30 days old. </p>