Dec 8, 2012

Query to find first and last day of previous month


The following query finds the first day and last day of the previous month. You can replace the SYSDATE to any other date such as Transaction Date, Receipt Date, Order Date, etc.

-------------------------------------------------------------------------------
-- Query to find first and last date of previous month
-------------------------------------------------------------------------------
SELECT TRUNC (ADD_MONTHS (SYSDATE, -1), 'MM') "First Day of Previous Month",
       TRUNC (SYSDATE, 'MM') - 1              "Last Day of Previous Month",
       TRUNC (SYSDATE, 'MM')                  "First Day of Current Month",
       TRUNC (LAST_DAY (SYSDATE))             "Last Day of Current Month"
  FROM DUAL;

No comments: