title: Check if variable is a valid date with PHP
body: <p>I am working on a script that will import some data from a CSV file. As I am doing this I want to be able to check a variable to see if it is a valid date string. </p>
  
  <p>I have seen several ways to check if a sting is a date, but most of them require you to now the format. I will not know the format that the date will in. </p>
  
  <p>right now I am using strtotime(), but this fails to easily </p>
  
  <pre><code>$field ="May";
  if(strtotime($field)){
      echo "This is a date";
  }
  </code></pre>
  
  <p>In this case, "May" was the persons first name, and not a date at all. </p>
  
  <p>Can any one recommend more reliable function? </p>
  
  <p><strong>Edit based on questions from some of you.</strong> </p>
  
  <p>For a variable to pass as a "date" in my case, it would need to be specific to a day/month/year, so just "May" would be to vague to count. </p>
  
  <p>Based on that and Pauls good point below we can also test to see if the string contains a number, such as </p>
  
  <pre><code>$field ="May";
  if(strtotime($field) &amp;&amp; 1 === preg_match('~[0-9]~', $field)){
      echo "This is a date";
  }else{
      echo "Nope not a date";
  }
  </code></pre>
  
  <p>This seems to cover my immediate needs, but can any one spot any issues or suggest improvements? </p>