与日期相关的几个常用函数
与日期相关的几个常用函数
与日期相关的几个常用的函数:
ADD_MONTHS 增加或者减少月
www.zzzyk.com
[sql]
SQL> select add_months(to_date('2013-01-01','yyyy-mm-dd'),4) as newMonth from dual;
NEWMONTH
--------------
01-5月 -13
LAST_DAY 得到当前月的最后一天 www.zzzyk.com
[sql]
SQL> select last_day(to_date('2013-01-01','yyyy-mm-dd')) as lastday from dual;
LASTDAY
--------------
31-1月 -13
MONTHS_BETWEEN(date2,date1) 判断两个月之间差几个月
www.zzzyk.com
[sql]
SQL> edit
已写入 file afiedt.buf
1 select months_between(to_date('2013-01-01','yyyy-mm-dd'),
2 to_date('2013-12-01','yyyy-mm-dd')) as monthsBetween
3* from dual
SQL> run
1 select months_between(to_date('2013-01-01','yyyy-mm-dd'),
2 to_date('2013-12-01','yyyy-mm-dd')) as monthsBetween
3* from dual
MONTHSBETWEEN
-------------
-11
NEXT_DAY(date,day) 得到日期的下一个周几
[sql]
SQL> select next_day(to_date('2013-01-08','yyyy-mm-dd'),'星期四') from dual;
NEXT_DAY(TO_DA
--------------
10-1月 -13