Thursday, July 16, 2015

First and last day of previous Month using Oracle SQL

To get the First and last day of previous month use following code snippet::

a) SYSDATE
select trunc(trunc(SYSDATE,'MM')-1,'MM') "First Day of Last Month",trunc(sysdate,'MM')-1 "Last Day of Last Month" from dual;

 b)For any Input Date::
select trunc(trunc(TO_DATE('01-JAN-15','DD-MON-YYYY'),'MM')-1,'MM') "First Day of Last Month",trunc(sysdate,'MM')-1 "Last Day of Last Month" from dual;

Where '01-JAN-2015' is the input Date

No comments:

Post a Comment