Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

mysql - im trying to compare between two dates 'Saturday, May 1, 2017' and '2017-07-23' but the first one is stored as string


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
set @d ='Saturday, May 1, 2017';

select case
            when str_to_date(@d,'%W, %M %d, %Y') < '2017-07-23' then true else false end testit;

+--------+
| testit |
+--------+
|      1 |
+--------+
1 row in set (0.001 sec)

Assuming the month is not abbreviated and all date_times are in the same format ,2 facts that should be included in your question. https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...