Skip to main content

First day, last date of week, last date of month, last date of quarter and last date of year using Oracle date function

Gets First day, last date of week, last date of month, last date of quarter, last date of year using oracle date functions. 

--First day of current week
SELECT TRUNC (SYSDATE, 'Day') first_day_of_current_week
  FROM DUAL;



--First day of next week
SELECT TRUNC (SYSDATE + 7, 'Day') first_day_of_next_week
  FROM DUAL;

--First day of previous week
SELECT TRUNC (SYSDATE - 7, 'Day') first_day_of_previous_week
  FROM DUAL;

--First day of current month
SELECT TRUNC (SYSDATE, 'Month') first_day_of_current_month
  FROM DUAL;

--First day of previous month
SELECT TRUNC (TRUNC (SYSDATE, 'Month') - 1, 'Month') first_day_of_previous_month
  FROM DUAL;

--First day of next month
SELECT TRUNC (LAST_DAY (SYSDATE) + 1, 'Month') first_day_of_next_month
  FROM DUAL;

--First day of current year
SELECT TRUNC (SYSDATE, 'Year') first_day_of_current_year
  FROM DUAL;

--First day of previous year
SELECT TRUNC (TRUNC (SYSDATE, 'Year') - 1, 'Year') first_day_of_previous_year
  FROM DUAL;

--First day of next year
SELECT ADD_MONTHS (TRUNC (SYSDATE, 'Year'), 12) first_day_of_next_year
  FROM DUAL;

-- First Day of Current quater 
SELECT TRUNC (SYSDATE, 'Q') first_day_of_current_quater
  FROM DUAL;

--  First Day of Previous Quarter
SELECT ADD_MONTHS (TRUNC (SYSDATE, 'Q'), -3) first_day_of_previous_quarter
  FROM DUAL;

--  First Day of Next Quarter
SELECT ADD_MONTHS (TRUNC (SYSDATE, 'Q'), 3) first_day_of_next_quarter
  FROM DUAL;

--Last day of current week
SELECT TRUNC (SYSDATE, 'Day') + 6 last_day_of_current_week
  FROM DUAL;

--Last day of next week
SELECT TRUNC (SYSDATE + 7, 'Day') + 6 last_day_of_next_week
  FROM DUAL;

--Last day of previous week
SELECT TRUNC (SYSDATE - 7, 'Day') + 6 last_day_of_previous_week
  FROM DUAL;

--Last day of current month
SELECT LAST_DAY (TRUNC (SYSDATE, 'Month')) last_day_of_current_month
  FROM DUAL;

--Last day of previous month
SELECT LAST_DAY (TRUNC (TRUNC (SYSDATE, 'Month') - 1, 'Month')) last_day_of_previous_month
  FROM DUAL;

--Last day of next month
SELECT LAST_DAY (TRUNC (LAST_DAY (SYSDATE) + 1, 'Month')) last_day_of_next_month
  FROM DUAL;

--Last day of current year
SELECT LAST_DAY (ADD_MONTHS (TRUNC (SYSDATE, 'Year'), 11)) last_day_of_current_year
  FROM DUAL;

--Last day of previous year
SELECT LAST_DAY (ADD_MONTHS (TRUNC (TRUNC (SYSDATE, 'Year') - 1, 'Year'), 11)) last_day_of_previous_year
  FROM DUAL;

--Last day of next year
SELECT LAST_DAY (ADD_MONTHS (TRUNC (TRUNC (SYSDATE, 'Year') - 1, 'Year'), -13)) last_day_of_next_year
  FROM DUAL;

-- Last Day of Current quater 
SELECT LAST_DAY (ADD_MONTHS (TRUNC (SYSDATE, 'Q'), 2)) last_day_of_current_quater
  FROM DUAL;

--  Last Day of Previous Quarter
SELECT TRUNC (SYSDATE, 'Q') - 1 last_day_of_previous_quarter
  FROM DUAL;

--  Last Day of Next Quarter
SELECT LAST_DAY (ADD_MONTHS (TRUNC (SYSDATE, 'Q'), 5)) last_day_of_next_quarter
  FROM DUAL;

-- Cheers !!!

Comments

Popular posts from this blog

ORA-01033 Oracle initialization or shutdown in progress

ORA-01033 Oracle initialization or shutdown in progress When you connect oracle 12c plug gable database, Thus time you have get oracle initialization or shutdown in progress error. This error occurred because pluggable database are not initialized. To fix this error connect as sysdba and run  ALTER PLUGGABLE DATABASE ALL OPEN    command. ALTER PLUGGABLE DATABASE ALL OPEN Thanks.

Checking operating system version: must be 5.0, 5.1 or 5.2 Actual 6.1 Failed

This error occurred when we are installing old oracle software in latest OS (Operating System).   Basically Its’s occurring on windows platform.

AFTER LOGON Trigger not perfectly working

AFTER LOGON not perfectly working.  I have tried it on single instance oracle 12c database it's perfectly work but it's not perfectly working on multi instance Oracle 12c database. I have submitted this matter in oracle forum but not found any perfect answer. Do you know why  it's not working ???