--Query to Select the First Day and Last Day of the Current Month
SELECT Trim(To_date(Last_day(SYSDATE), 'DD/MM/YYYY')) AS lastday
FROM dual;
SELECT Trunc(( SYSDATE ), 'month') AS FirstDay
FROM dual;
--Query to Select the First Day and Last Day of the last month of Given Date
SELECT Trunc(Trunc(To_date(:P_DATE), 'month') - 1, 'month')
Last_month_first_day1,
Trunc(Add_months(To_date(:P_DATE), -1), 'month')
Last_month_first_day2
FROM dual;
SELECT Trunc(To_date(:P_DATE), 'month') - 1 Last_month_last_day1,
Last_day(Add_months(To_date(:P_DATE), -1)) Last_month_last_day2
FROM dual;
--Query to Select the First Day and Last Day of the 2nd last month of Given Date
SELECT Trunc(Add_months(To_date(:P_DATE), -2), 'month') second_month_first_day
FROM dual;
SELECT Last_day(Add_months(To_date(:P_DATE), -2)) second_month_last_day
FROM dual;
--Query to Select the First Day and Last Day of the 3rd last month of Given Date
SELECT Trunc(Add_months(To_date(:P_DATE), -3), 'month') thrid_month_first_day
FROM dual;
SELECT Last_day(Add_months(To_date(:P_DATE), -3)) third_month_last_day
FROM dual;
Friday, 11 June 2021
QUERY FIRST DAY & LAST DAY OF MONTHs FOR GIVEN DATE IN ORACLE
Subscribe to:
Posts (Atom)