title: MySQL date validity
body: <p>Does MySQL provide any function which verifies the validity of a date? The <code>DATE</code> function returns <code>NULL</code> upon provision of the invalid date 2013-02-30 for example. However, I am also using <code>STR_TO_DATE</code> simultaneously, which mysteriously stops <code>DATE</code> from working correctly.</p>
  
  <pre><code>SELECT DATE('2013-02-30'); NULL
  SELECT STR_TO_DATE('2013-02-30', '%Y-%m-%d'); NOT NULL
  SELECT DATE('2013-02-40'); NULL
  SELECT STR_TO_DATE('2013-02-40', '%Y-%m-%d'); NULL
  SELECT DATE(STR_TO_DATE('2013-02-30', '%Y-%m-%d')); NOT NULL
  </code></pre>
  
  <p>Why does <code>STR_TO_DATE</code> halt <code>DATE</code>'s functionality and is there some workaround to verify if a date is valid when using <code>STR_TO_DATE</code> (which I am obligated to use)?</p>
  
  <p>I have stumbled upon the answer in the meantime: apparently the <code>DATE</code> function skips a few validation checks, when the data type is already that of 'date' (<code>STR_TO_DATE</code> converts strings to date data types). Therefore, converting the date to a string after having parsed it to the correct format with <code>STR_TO_DATE</code>, does the trick:</p>
  
  <p><code>@valid_date = NOT ISNULL(DATE(CONVERT(STR_TO_DATE('2013-02-29', '%Y-%m-%d'), CHAR)))</code>.</p>