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

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.

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

Windows 8 boot loader corrupted

Problem:     Installed Windows 7 and Windows 8 in EFI mode on a hard disk some days past. Today, the boot loader is absent or corrupted. At present have the Windows 8 installer on a flash drive and tried using the Automatic Repair option to repair the boot loader but it didn't do anything. The Startup Repair option is also absent in the Windows 8 installer. How I can repair or recreate the EFI boot loader from the Command Prompt? BCDEDIT   returns the following message: The requested system device cannot be found. Solution: Firstly, boot from a UEFI Windows 8 recovery disk (CD/DVD/USB) - I found that the automated recovery process didn't find the correct Windows partition, nor when I managed to add it to BCD settings would it make it reliably boot-able e.g. using BCDEDIT I got it to find and launch the Windows partition but it refused to cold boot or would not "keep" the settings after a 2nd reboot or power off. Go into the Advanced option