`

时间比较

阅读更多
时间比较,

一种,转换为date格式比较
情况一,数据库字段类型本来就是date类型
create table time_825(
    timenow date
)

select
 * 
 from time_825
 where timenow>to_date('2010-08-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
 and timenow<to_date('2010-08-20 08:20:00','yyyy-mm-dd hh24:mi:ss');
 
 
情况二,数据库字段类型是varchar型:

create table time_826(
    timenow varchar2(256)
)

select
 * 
 from time_826
 where to_date(timenow,'yyyy-mm-dd hh24:mi:ss')>to_date('2010-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
 and  to_date(timenow,'yyyy-mm-dd hh24:mi:ss')<to_date('2010-08-04 08:20:00','yyyy-mm-dd hh24:mi:ss');


二种,转换为字符串来比较:


  


  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics