title: MySQL CAST as DATE
body: <p>I'm trying to understand what casting a value to the DATE type in MySQL does. Here are some things I have tried:</p>
  <pre><code>SELECT CAST('3' AS DATE);
  -- null
  
  SELECT CAST(3 AS DATE);
  -- null
  
  SELECT CAST('2014-07-01 19:00:01' AS DATE);
  -- 2014-07-01
  
  SELECT DATE('2014-07-01 19:00:01');
  -- 2014-07-01
  
  SELECT CAST('2014-07-01' AS DATE);
  -- 2014-07-01
  
  SELECT DATE('2014-07-01');
  -- 2014-07-01
  
  SELECT CAST('2014-07-50' AS DATE);
  -- null
  
  SELECT DATE('2014-07-50');
  -- null
  
  SELECT DATE(''), CAST('' AS DATE), DATE(0), CAST(0 AS DATE);
  -- null, null, 0000-00-00, 0000-00-00
  </code></pre>
  <p>Everything I've tried seems to either convert it to <code>null</code> if it's invalid or return the date portion of the string if it's a valid date. I've even tried dates with slashes and other formats, same results.</p>
  <p>What's the difference between using the <a href="https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_date" rel="noreferrer"><code>DATE(expr)</code></a> function and the <a href="https://dev.mysql.com/doc/refman/5.6/en/cast-functions.html#function_cast" rel="noreferrer"><code>CAST(expr AS DATE)</code></a>?</p>
  <blockquote>
  <p><code>DATE(expr)</code>: Extracts the date part of the date or datetime expression expr.</p>
  <p><code>CAST(expr AS type)</code>: The <code>CAST()</code> function takes an expression of any type and produces a result value of a specified type, similar to <code>CONVERT()</code></p>
  </blockquote>
  <p>Similarly, the same question can be asked about times with <code>TIME(expr)</code> and <code>CAST(expr AS TIME)</code>.</p>