千家信息网

oracle日期函数部分用法

发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,接上贴ORACLE日期时间函数大全日期和字符转换函数用法(to_date,to_char)select to_char(sysdate,'yyyy-mm-dd hh34:mi:ss') as nowT
千家信息网最后更新 2025年01月23日oracle日期函数部分用法

接上贴ORACLE日期时间函数大全

日期和字符转换函数用法(to_date,to_char)

select to_char(sysdate,'yyyy-mm-dd hh34:mi:ss') as nowTime from dual; //日期转化为字符串
select to_char(sysdate,'yyyy') as nowYear from dual; //获取时间的年
select to_char(sysdate,'mm') as nowMonth from dual; //获取时间的月
select to_char(sysdate,'dd') as nowDay from dual; //获取时间的日
select to_char(sysdate,'hh34') as nowHour from dual; //获取时间的时
select to_char(sysdate,'mi') as nowMinute from dual; //获取时间的分
select to_char(sysdate,'ss') as nowSecond from dual; //获取时间的秒


求某天是星期几
SQL> select to_char(to_date('2015-10-27','yyyy-mm-dd'),'day') from dual;

TO_CHA
------
星期二


两个日期间的天数
SQL> select floor(sysdate - to_date('20020405','yyyymmdd')) from dual;

FLOOR(SYSDATE-TO_DATE('20020405','YYYYMMDD'))
---------------------------------------------
4949


年月日的处理
select older_date,
newer_date,
years,
months,
abs(
trunc(
newer_date-
add_months( older_date,years*12+months )
)
) days from ( select
trunc(months_between( newer_date, older_date )/12) YEARS,
mod(trunc(months_between( newer_date, older_date )),12 ) MONTHS,
newer_date,
older_date
from (
select hiredate older_date, add_months(hiredate,rownum)+rownum newer_date
from emp
)
)


处理月份天数不定的办法
select to_char(add_months(last_day(sysdate) +1, -2), 'yyyymmdd'),last_day(sysdate) from dual

原文地址;http://plat.delit.cn/thread-183-1-1.html

转载请注明出处;

撰写人:度量科技http://www.delit.cn

0