当前位置:Gxlcms > 数据库问题 > 有关Sql中时间范围的问题

有关Sql中时间范围的问题

时间:2021-07-01 10:21:17 帮助过:15人阅读

to_char(sysdate,yyyy-mm-dd hh24:mi:ss) as Nowtime from dual;
//2020-04-02 16:25:42

1、将日期转换为字符串再比较

select sysdate nowtime from dual where to_char(sysdate,yyyymmdd hh24:mi:ss) between 20200401 and 20200403;
//02-APR-20,时间范围是2020-04-01 00:00:00 至 2020-04-03 00:00:00
select sysdate time from dual where to_char(sysdate,yyyymmdd) between 20200402 and 20200402;
//02-APR-20,时间范围是2020-04-02 00:00:00 至 2020-04-02 24:00:00 

2、将字符串转化为日期再比较

select sysdate nowtime from dual where sysdate between to_date(20200401,yyyyMMdd) and to_date(20200403,yyyyMMdd);
//02-APR-20,时间范围是2020-04-01 00:00:00 至 2020-04-03 00:00:00

注意:如果不在字符串中指定时间则转换的时间默认为0点,所以前后日期一致则时间间隔为0。

select to_char(to_date(20200402,yyyyMMdd),yyyyMMdd hh24:mi:ss) nowtime from dual;
//20200402 00:00:00

 

有关Sql中时间范围的问题

标签:指定   color   时间间隔   div   where   style   dual   sele   apr   

人气教程排行