MySQL Forums
Forum List  »  Newbie

Re: Filtering Entries by Complex Date
Posted by: Rick James
Date: November 04, 2014 07:25PM

What do you get from
SELECT needDate,
   CASE WHEN needDate IS NULL THEN '20120101'
   WHEN CHAR_LENGTH(needDate) > 6 THEN DATE_FORMAT(STR_TO_DATE(needDate, '%m/%d/%Y'), '%Y%m%d') 
   WHEN CHAR_LENGTH(needDate) > 4 THEN DATE_FORMAT(STR_TO_DATE(needDate, '%Y%m'),     '%Y%m01')
   ELSE                                DATE_FORMAT(STR_TO_DATE(needDate, '%Y'),       '%Y0101')
   END  AS ymd
 FROM courses
 HAVING ymd
   BETWEEN DATE_FORMAT(STR_TO_DATE('11/29/2013', '%m/%d/%Y'), '%Y%m%d')
       AND DATE_FORMAT(STR_TO_DATE('06/17/2014', '%m/%d/%Y'), '%Y%m%d');
?

What needDate value(s) do not work right?

Options: ReplyQuote


Subject
Written By
Posted
Re: Filtering Entries by Complex Date
November 04, 2014 07:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.