简体   繁体   中英

How to use unix_timestamp( ) function on date comparison on string value

How to use unix_timestamp( ) function on date comparison on data type string that in a format of 1/1/2019. The goal is to show all the dates before 1/1/2010. Here is what I'm trying

SELECT work_date FROM table WHERE work_date <= UNIX_TIMESTAMP('2010-01-01');

... date comparison on data type string that in a format of '1/1/2019' . The goal is to show all the dates before '1/1/2010' .

I don't really see why you would want to specifically use UNIX_TIMESTAMP() for that purpose. Basically you just need to convert your formated string to a date. For that, you can use STR_TO_DATE() .

Consider:

SELECT work_date 
FROM table 
WHERE STR_TO_DATE(work_date, '%e/%c/%Y') <= '2010-01-01';

NB: it is impossible to tell if your string date format starts with the month or with the day; the above format stands for the second option, if you want it the other way around then that would be '%c/%e/%Y' instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM