Datetime comparison size in mysql

method one:

Use the unix_timestamp function to convert the character time into a unix timestamp
select * from t1 where unix_timestamp(time1) > unix_timestamp('2011-03-03 17:39:05') and unix_timestamp(time1) < unix_timestamp('2011 -03-03 17:39:52');
 

Method Two:

time1 between '2011-03-03 17:39:05' and '2011-03-03 17:39:52';

 

Method three:

You can convert the datetime type into a date type and then compare it.
For example: convert(date, table name. datetime column name) >= convert(date, table name. datetime column name)

 

Reference from: http://blog.sina.com.cn/s/blog_43eb83b90102e0mx.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326154080&siteId=291194637