--First day of current week(sunday)
select TRUNC(SYSDATE, 'Day') from dual;
--First day of next week(sunday)
select TRUNC(SYSDATE+7 , 'Day') from dual;
--First day of previous week(sunday)
select TRUNC(SYSDATE-7 , 'Day') from dual;
--First day of current month
select TRUNC(SYSDATE , 'Month') from dual;
--First day of previous month
select TRUNC(TRUNC(SYSDATE , 'Month')-1 , 'Month') from dual;
--First day of next month
select TRUNC(LAST_DAY(SYSDATE)+1 , 'Month') from dual;
--First day of current year
select TRUNC(SYSDATE , 'Year') from dual;
--First day of previous year
select TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year') from dual;
--First day of next year
select ADD_MONTHS(TRUNC(SYSDATE , 'Year'),12) from dual;
-- First Day of Current quater
select TRUNC(SYSDATE , 'Q') from dual;
-- First Day of Previous Quarter
select ADD_MONTHS(TRUNC(SYSDATE , 'Q'),-3) from dual;
-- First Day of Next Quarter
select ADD_MONTHS(TRUNC(SYSDATE , 'Q'),3) from dual;
--Last day of current week(sunday)
select TRUNC(SYSDATE, 'Day')+6 from dual;
--Last day of next week(sunday)
select TRUNC(SYSDATE+7 , 'Day')+6 from dual;
--Last day of previous week(sunday)
select TRUNC(SYSDATE-7 , 'Day')+6 from dual;
--Last day of current month
select LAST_DAY(TRUNC(SYSDATE , 'Month')) from dual;
--Last day of previous month
select LAST_DAY(TRUNC(TRUNC(SYSDATE , 'Month')-1 , 'Month')) from dual;
--Last day of next month
select LAST_DAY(TRUNC(LAST_DAY(SYSDATE)+1 , 'Month')) from dual;
--Last day of current year
select LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE , 'Year'),11)) from dual;
--Last day of previous year
select LAST_DAY(ADD_MONTHS(TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year'),11)) from dual;
--Last day of next year
select LAST_DAY(ADD_MONTHS(TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year'),-13)) from dual;
-- Last Day of Current quater
select LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE , 'Q'),2)) from dual;
-- Last Day of Previous Quarter
select TRUNC(SYSDATE , 'Q')-1 from dual;
-- Last Day of Next Quarter
select LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE , 'Q'),5)) from dual;
--Fetches the First day of previous,current and Upcoming months--
SELECT to_char(trunc(add_months(sysdate,-6),'mm') ,'DD-Mon-YYYY') FROM Dual;
--Fetches the Last day of previous,current and Upcoming months--
SELECT to_char(add_months(last_day(sysdate),-6),'DD-Mon-YYYY') FROM Dual;
--Fetches First Day of Previous,Current,Upcoming Months Query--
SELECT
TO_CHAR(TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-3))+1),'DD-MON-YY') AS "One Way"
, TO_CHAR(TRUNC(ADD_MONTHS(LAST_DAY(SYSDATE)+1,-3)),'DD-MON-YY') AS "Another Way"
FROM dual;
--fetches First Day of Previous,Current,Upcoming Dateandyear Query--
select trunc(add_months(sysdate,-2),'mm') as first_day from dual;
--fetches Last Day of Previous,Current,Upcoming Dateandyear Query--
SELECT add_months(last_day(sysdate),-1) FROM Dual;
--To get current month--
select to_char(sysdate,'MM') from dual;
--Fetches Previous,Current,Upcoming Months Query--
SELECT to_char(add_months(last_day(sysdate),-1),'MM') FROM Dual;
--Fetching Current,Previous and upcoming Year--
select TO_CHAR(add_months( to_date(SYSDATE), -1),'DD-Mon-YYYY') from dual;
select TRUNC(SYSDATE, 'Day') from dual;
--First day of next week(sunday)
select TRUNC(SYSDATE+7 , 'Day') from dual;
--First day of previous week(sunday)
select TRUNC(SYSDATE-7 , 'Day') from dual;
--First day of current month
select TRUNC(SYSDATE , 'Month') from dual;
--First day of previous month
select TRUNC(TRUNC(SYSDATE , 'Month')-1 , 'Month') from dual;
--First day of next month
select TRUNC(LAST_DAY(SYSDATE)+1 , 'Month') from dual;
--First day of current year
select TRUNC(SYSDATE , 'Year') from dual;
--First day of previous year
select TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year') from dual;
--First day of next year
select ADD_MONTHS(TRUNC(SYSDATE , 'Year'),12) from dual;
-- First Day of Current quater
select TRUNC(SYSDATE , 'Q') from dual;
-- First Day of Previous Quarter
select ADD_MONTHS(TRUNC(SYSDATE , 'Q'),-3) from dual;
-- First Day of Next Quarter
select ADD_MONTHS(TRUNC(SYSDATE , 'Q'),3) from dual;
--Last day of current week(sunday)
select TRUNC(SYSDATE, 'Day')+6 from dual;
--Last day of next week(sunday)
select TRUNC(SYSDATE+7 , 'Day')+6 from dual;
--Last day of previous week(sunday)
select TRUNC(SYSDATE-7 , 'Day')+6 from dual;
--Last day of current month
select LAST_DAY(TRUNC(SYSDATE , 'Month')) from dual;
--Last day of previous month
select LAST_DAY(TRUNC(TRUNC(SYSDATE , 'Month')-1 , 'Month')) from dual;
--Last day of next month
select LAST_DAY(TRUNC(LAST_DAY(SYSDATE)+1 , 'Month')) from dual;
--Last day of current year
select LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE , 'Year'),11)) from dual;
--Last day of previous year
select LAST_DAY(ADD_MONTHS(TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year'),11)) from dual;
--Last day of next year
select LAST_DAY(ADD_MONTHS(TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year'),-13)) from dual;
-- Last Day of Current quater
select LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE , 'Q'),2)) from dual;
-- Last Day of Previous Quarter
select TRUNC(SYSDATE , 'Q')-1 from dual;
-- Last Day of Next Quarter
select LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE , 'Q'),5)) from dual;
--Fetches the First day of previous,current and Upcoming months--
SELECT to_char(trunc(add_months(sysdate,-6),'mm') ,'DD-Mon-YYYY') FROM Dual;
--Fetches the Last day of previous,current and Upcoming months--
SELECT to_char(add_months(last_day(sysdate),-6),'DD-Mon-YYYY') FROM Dual;
--Fetches First Day of Previous,Current,Upcoming Months Query--
SELECT
TO_CHAR(TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-3))+1),'DD-MON-YY') AS "One Way"
, TO_CHAR(TRUNC(ADD_MONTHS(LAST_DAY(SYSDATE)+1,-3)),'DD-MON-YY') AS "Another Way"
FROM dual;
--fetches First Day of Previous,Current,Upcoming Dateandyear Query--
select trunc(add_months(sysdate,-2),'mm') as first_day from dual;
--fetches Last Day of Previous,Current,Upcoming Dateandyear Query--
SELECT add_months(last_day(sysdate),-1) FROM Dual;
--To get current month--
select to_char(sysdate,'MM') from dual;
--Fetches Previous,Current,Upcoming Months Query--
SELECT to_char(add_months(last_day(sysdate),-1),'MM') FROM Dual;
--Fetching Current,Previous and upcoming Year--
select TO_CHAR(add_months( to_date(SYSDATE), -1),'DD-Mon-YYYY') from dual;
No comments:
Post a Comment