oracle中时间的处理
1.格式化输出
<1>select to_char(sysdate,'yyyy/mm/dd') from dual;
显示结果:
2011/05/11
<2>select to_char(sysdate,'yyyy"年"mm"月"dd"月"') from dual;
显示结果:
2011年05月11月
2.日期推算处理
<1>指定日期该年的第一天
select trunc(sysdate,'YEAR') from dual
显示结果:
2011-1-1
该年的最后一天
select add_months(last_day(sysdate),12-to_char(sysdate,'mm')) from dual;
显示结果:
2011-12-31 10:35:21
<2>指定日期该月的第一天
select add_months(last_day(sysdate)+1,-1) from dual;
显示结果:
2011-5-1 10:44:14
select trunc(sysdate,'MONTH') from dual;
显示结果:
2011-5-1
指定日期该月的最后一天
s