Rumah > Artikel > pangkalan data > Oracle 中获取特定日期时间 (need to H)
SELECT TRUNC(TRUNC(SYSDATE-1,
SELECT TRUNC(TRUNC(SYSDATE-1, 'YEAR')-1, 'YEAR') FROM DUAL -- Get first day of last year, sysdate-1 indicate current day in DW case.
select add_months(trunc(sysdate, 'year'), 12) - (1 / 86400) from dual -- 得到当年最后一天最后时刻分秒。
SELECT TRUNC(TO_DATE('20110228', 'YYYYMMDD'), 'MONTH') AS FIRST_DAY_MONTH FROM DUAL --- 获取当前月的第一天
SELECT TRUNC(SYSDATE, 'MONTH') AS FIRST_DAY_CURRENT_MONTH FROM DUAL; -- 得系统当月第一天
--- 获得去年的上个月第一天到今年的上个月的最后一天的最后时间点。如当前为2011-09,,则返回2010-08-01 至2011-08-31 23:59:59
SELECT TRUNC(ADD_MONTHS(SYSDATE, -13), 'MONTH'), -- fist_day_of_previous_month_of_last_year
TRUNC(SYSDATE, 'MONTH') - (1 / 86400) -- end_datetime_of_last_month
FROM DUAL;
SELECT TRUNC(SYSDATE, 'MONTH') - (1 / 86400)FROM DUAL; -- 得系统上个月最后一天最后时间点
--- 获取指定月的上上一个月的起止日期段。
SELECT TRUNC(ADD_MONTHS(SYSDATE, -2), 'MONTH') AS fisrt_day_of_last_last_month,
Trunc(ADD_MONTHS(SYSDATE, -1), 'MONTH') - (1 / 86400) AS Last_Day_of_last_Last_Month
FROM DUAL;
SELECT TRUNC(ADD_MONTHS(to_date('20110220', 'yyyymmdd'), -2), 'MONTH') AS fisrt_day_of_last_last_month,
Trunc(ADD_MONTHS(to_date('20110220', 'yyyymmdd'), -1), 'MONTH') - (1 / 86400) AS Last_Day_of_last_Last_Month
FROM DUAL;
--- 获取上一天最后时刻点的二个方法
select (TRUNC(NEXT_DAY(SYSDATE, 1), 'DAY') - (1 / 86400)) - 3 from dual;
SELECT TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM-DD'), 'YYYY-MM-DD') - (1 / 86400) FROM DUAL;