获取当前的小时数 博客分类: 数据库
程序员文章站
2024-03-19 10:30:16
...
使用extract 函数获取时间信息的时候,小时数不能正确获取
例如:
select sysdate "date", extract(year from sysdate) "year" ,
extract(month from sysdate)"month",
extract(day from sysdate)"day",
extract(hour from systimestamp)"hour",
extract(minute from systimestamp)"minute",
extract(second from systimestamp)"second"
from dual
查询结果:
date year month day hour minute second
2017/2/16 15:47:43 2017 2 16 7 47 43.028
明明是15时,查询的结果却是7时。why?
因为: extract是按照时区0来取的,所以和当前系统的时间的小时值不符。
select extract(hour from cast(systimestamp as timestamp)) "hour" from dual;这个语句就可以取到正确的小时。
例如:
select sysdate "date", extract(year from sysdate) "year" ,
extract(month from sysdate)"month",
extract(day from sysdate)"day",
extract(hour from systimestamp)"hour",
extract(minute from systimestamp)"minute",
extract(second from systimestamp)"second"
from dual
查询结果:
date year month day hour minute second
2017/2/16 15:47:43 2017 2 16 7 47 43.028
明明是15时,查询的结果却是7时。why?
因为: extract是按照时区0来取的,所以和当前系统的时间的小时值不符。
select extract(hour from cast(systimestamp as timestamp)) "hour" from dual;这个语句就可以取到正确的小时。