1. 程式人生 > >mysql中datetime比較大小

mysql中datetime比較大小

select sum(studychj) as tofflinejz from afterline where checkflag=1 and studytype=1 and studybegin>='2010-01-01 00:00:00' and studyend<='2010-12-01 00:00:00' and username='01009'


這麼寫不報錯,但得出結果不準確

方法一:

你也可以:
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');
就是用unix_timestamp函式,將字元型的時間,轉成unix時間戳。個人覺得這樣比較更踏實點兒。

方法二

select DATE_FORMAT('2015-06-06 23:22:26','%Y-%