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.

Oracle forms 11g default configuration file formsweb.cfg

#formsweb.cfg defines parameter values used by the FormsServlet # formsweb.cfg defines parameter values used by the FormsServlet (frmservlet) # This section defines the Default settings. Any of them may be overridden in the # following Named Configuration sections. If they are not overridden, then the # values here will be used. # The default settings comprise two types of parameters: System parameters, # which cannot be overridden in the URL, and User Parameters, which can. # Parameters which are not marked as System parameters are User parameters. # SYSTEM PARAMETERS

No free space to rebalance ASM disk group

   To day we found below warning message from Exadata system: Warning: Software Alert 92_1 Event Time 2025-01-23T16:19:57+06:00 Description Insufficient free space to rebalance the ASM disk group: RECOC1 Affected Server Name ******* Server Model Oracle Corporation ORACLE SERVER X9-2 Chassis Serial Number 2217XCD00X Release Version 24.1.5.0.0.241016 RPM Version 24.1.5.0.0.241016 Recommended Action Please refer to MOS Doc 1551288.1                                                                                                I am search  Chatgpt and found below solutions. Rebalancing an ASM (Automatic Storage Management) disk group in Oracle is a process where the disk group redistributes data...