title: mysql - validate/correct based on date format
body: <p>I'm querying a mysql database where string fields are being used to enter date information (this is due to configured 3rd party application that is importing the data.)  I recently ran into an issue where I am using the following to query 2 different fields.  If the first is Null then it moves onto the next, and then reports an error if both are null:</p>
  <pre><code>IFNULL(IFNULL(NULLIF(DATE_FORMAT(str_to_date(REPLACE(so.customfields-&gt;&gt;'$.&quot;59&quot;.value',&quot;-&quot;,&quot;/&quot;),'%m/%d/%Y'),'%m-%d-%Y'), &quot;00-00-0000&quot;), NULLIF(DATE_FORMAT(str_to_date(REPLACE(so.customfields-&gt;&gt;'$.&quot;61&quot;.value',&quot;-&quot;,&quot;/&quot;),'%m/%d/%Y'),'%m-%d-%Y'), &quot;00-00-0000&quot;)), &quot;Missing Requested Ship and Earliest Ship Date&quot;) as &quot;Earliest Ship Date&quot;,
  </code></pre>
  <p>This works great if the format is correct, for example: &quot;6/24/2022&quot; or &quot;6-24-2022&quot;</p>
  <p>The issue that I ran into today is that a user input error caused the result to be null for custom field 59 due to the user input: &quot;6/24//2022&quot;</p>
  <p>Does anyone know a method to validate that the date format is correct, and if not to remove extra characters like the extra &quot;/&quot; so that it is correct?</p>