mysql中datetime比较大小

方法一:

用unix_timestamp函数,将字符型的时间,转成unix时间戳
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');
 

方法二:

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

方法三:

可以将datetime类型转换成date类型再进行比较
例如:convert(date,表名.datetime列名) >= convert(date,表名.datetime列名)

参考来自:http://blog.sina.com.cn/s/blog_43eb83b90102e0mx.html

猜你喜欢

转载自my.oschina.net/zjllovecode/blog/1809474