|
1. 日期比较
数据库有一个日期栏位:Date类型 create_date ,
1.1想要获取日期为今天的所有记录信息,
select * from table1 t where t.create_date > sysdate -1
:sysdate -1 表示昨天, 日期可以用>=<比较.
sysdate 表示当前时间 : 2011-3-5 11:47:56
1.2 获取某个时刻之后的所有记录
使用 to_date( * , * ) 函数
获取3.5日8点后的所有记录
select count(*) from messages where create_date > to_date('2011-3-5 8:00:00','yyyy-mm-dd hh24:mi:ss');
1.3 获取某段时间内的记录
select count(*)
from messages
where create_date > to_date('2011-3-5 8:00:56', 'yyyy-mm-dd hh24:mi:ss')
and create_date < to_date('2011-3-5 10:22:56', 'yyyy-mm-dd hh24:mi:ss')
:使用to_date()可以把日期转化为 可以比较大小的数字
|
|
|