0%
某个日期加几个月:ADD_MONTHS(DATE1,A)
1 2
| select add_months(sysdate,3) from dual;
|
计算出某个时间下一周的第几天:NEXT_DAY(DATE1,4)
1 2
| select next_day(sysdate,5) from dual;
|
计算某个日期所在月份的最后一天:LAST_DAY(DATE1)
1 2
| SELECT LAST_DAY(SYSDATE) FROM DUAL;
|
取某个日期的下一个月、下一年的第一天:ROUND(DATE,’MONTH’)、ROUND(DATE,’YEAR’)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
select round(to_date('2020-03-15','YYYY-MM-DD'),'month') from dual;
select round(to_date('2020-03-16','YYYY-MM-DD'),'month') from dual;
select round(to_date('2020-06-30','YYYY-MM-DD'),'year') from dual;
select round(to_date('2020-07-1','YYYY-MM-DD'),'year') from dual;
|
取某个日期的当前月、当前年的第一天:TRUNC(DATE,’MONTH’)、TRUNC(DATE,’YEAR’)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
select TRUNC(to_date('2020-03-15','YYYY-MM-DD'),'month') from dual;
select TRUNC(to_date('2020-03-16','YYYY-MM-DD'),'month') from dual;
select TRUNC(to_date('2020-06-30','YYYY-MM-DD'),'year') from dual;
select TRUNC(to_date('2020-07-1','YYYY-MM-DD'),'year') from dual;
|
两个日期相减得:天数
1 2
| select to_date('08/06/2015','mm/dd/yyyy')-to_date('07/01/2015','mm/dd/yyyy') from dual d;
|
两个日期相减得:月数 months_between()
1 2 3 4
| select trunc(months_between(to_date('08/06/2015','mm/dd/yyyy'),to_date('07/01/2015','mm/dd/yyyy'))) from dual d;
select trunc(months_between(to_date('07/05/2015','mm/dd/yyyy'),to_date('07/01/2015','mm/dd/yyyy'))) from dual d;
|
两个日期相减得:年数 months_bewwent() / 12
1 2
| select trunc(months_between(to_date('07/01/2014','mm/dd/yyyy'),to_date('07/01/2015','mm/dd/yyyy')) / 12) from dual d;
|