简体   繁体   中英

How to use greater than operator in mysql query with date which is in the type varchar

I have a mysql table task with fields

tid int(10),
sdate varchar(25), -- `30-08-2017`
tname varchar(30)`

I want to select details from the table with following condition. Here is my sql query.

Select * from task where sdate < '07-09-2017';

But I can't get any records with this condition. Please any other solution for this issue...Thanks to all in advance

It's better idea to change your column data type to DateTime or what ever your need than using a query like this one:

SELECT * FROM task
WHERE STR_TO_DATE(sdate, '%d-%m-%Y') < STR_TO_DATE('07-09-2017', '%d-%m-%Y');

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