2012-12-11 174 views
1

我有以下查詢:MySQL-截斷日期,時間查詢

select * from player_source 
where source is not null 

導致

ID  create_dtime 
001  2012-10-16 16:13:27 
002  2012-12-10 16:13:27 

等等...

我要篩選的查詢,以便它只返回結果的create_dtime大於或等於2012年12月3日,並且小於或等於2012年12月9日。

我嘗試使用

select * from player_source 
where source is not null 
and Create_Dtime >= To_Date('2012-Dec-03','yyyy-mon-dd') 
and Create_Dtime <= To_Date('2012-Dec-09','yyyy-mon-dd') 

使用我的Oracle根,但它似乎沒有工作。有什麼想法嗎?

+0

的http:// dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date –

回答

2

查詢:

select * 
from player_source 
where source is not null 
and Create_Dtime >= '2012-10-03' 
and Create_Dtime <= '2012-10-09' 
0

試試這個

select * 
from player_source 
where source is not null 
and Create_Dtime >= '2012-Dec-03' 
and Create_Dtime <= '2012-Dec-09' 
0

的語法是:

select * from player_source 
where source is not null 
and Create_Dtime > '2012-12-03' 
and Create_Dtime <= '2012-12-09' 

,或者更簡潔:

select * from player_source 
where source is not null 
and Create_Dtime > '2012-12-03' BETWEEN 
and '2012-12-09'