mysql中datetime比较大小问题有如下方法:
方法一:
你也可以:
select * from crowd_textpage where username='carina' and status=4 and unix_timestamp(inputtime) >= unix_timestamp('2013-12-01') and unix_timestamp(inputtime) <= unix_timestamp('2013-12-20'); delete from crowd_textpage where textname like '合肥%' and time>='2014-03-08' and time<'2014-03-09'; update crowd_textpage set status=2 where status=3 and unix_timestamp(time) >= unix_timestamp('2013-12-28') and unix_timestamp(time) <= unix_timestamp('2013-12-31');///更新把2013-12-28号到2013-12-31状态为3的更新成状态为2! 就是用unix_timestamp函数,将字符型的时间,转成unix时间戳。个人觉得这样比较更踏实点儿。 update `crowd_textpage` set status=2 WHERE STATUS =3 AND url LIKE "%58.com%" AND unix_timestamp( time ) >= unix_timestamp( '2014-03-24' ) AND unix_timestamp( time ) <= unix_timestamp( '2014-03-25' ) 方法二:
time1 between '2013-12-01 17:39:05' and '2013-12-020 17:39:52';
你也可以:
select * from crowd_textpage where username='carina' and status=4 and unix_timestamp(inputtime) >= unix_timestamp('2013-12-01') and unix_timestamp(inputtime) <= unix_timestamp('2013-12-20'); delete from crowd_textpage where textname like '合肥%' and time>='2014-03-08' and time<'2014-03-09'; update crowd_textpage set status=2 where status=3 and unix_timestamp(time) >= unix_timestamp('2013-12-28') and unix_timestamp(time) <= unix_timestamp('2013-12-31');///更新把2013-12-28号到2013-12-31状态为3的更新成状态为2! 就是用unix_timestamp函数,将字符型的时间,转成unix时间戳。个人觉得这样比较更踏实点儿。 update `crowd_textpage` set status=2 WHERE STATUS =3 AND url LIKE "%58.com%" AND unix_timestamp( time ) >= unix_timestamp( '2014-03-24' ) AND unix_timestamp( time ) <= unix_timestamp( '2014-03-25' ) 方法二:
time1 between '2013-12-01 17:39:05' and '2013-12-020 17:39:52';
方法三:
可以讲datetime类型转换成date类型再进行比较
例如:convert(date,表名.datetime列名) >= convert(date,表名.datetime列名)
三种方法待求证,总之是不要用字符串这么直接比
转载请注明转自:运达's blog 原文地址: http://www.yunda51.com/1130.html
运达兄弟!你终于回来啦!
我复活啦,哈哈~
新年快乐
同乐同乐~
数据库啊,我还不会呢,过来学习学习
没事可以互相探讨~
我终于又出来冒泡了 圣诞快乐哦~不过此次前来,俺有一事相求——俺公司在新浪微博上做了个微活动,转发就有机会得话费,博主要是有新浪微博,就帮忙捧个场吧! http://event.weibo.com/9037608 俺先谢谢啦!帮俺增加点人气呀
圣诞快乐,哈哈,刚才我已经转发了!