title: PHP: Validate date from user input
body: <p>in my application the user inputs a date (if he wants with hours and minutes specification) which gets saved in a variable like this:</p>
  
  <pre><code>$userdate = new dateTime($dateraw);
  </code></pre>
  
  <p>Now I want to check if the input is valid, the following opportunities should be possible:</p>
  
  <blockquote>
    <p>20.01.2015 12:00<br />
    2015-01-20 12:00</p>
  </blockquote>
  
  <p>And it is also very important to check if the users submitted a valid day and month.</p>
  
  <blockquote>
    <p>valid day = a number but not over 31<br />
    valid month = a number but not over 12</p>
  </blockquote>
  
  <p>I tried something like that</p>
  
  <pre><code>if ($userdate-&gt;format('%a') &gt; 31 ) {
  echo "Your day input is not valid.";
  }
  </code></pre>