MySQL-在查询中截断日期时间

时间:2012-12-11 21:07:38

标签: mysql sql

我有以下查询:

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根,但似乎没有用。有什么想法吗?

3 个答案:

答案 0 :(得分:2)

查询:

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

答案 1 :(得分:0)

试试这个

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

答案 2 :(得分: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'