| How to get first and last day for 13 month back [message #645006] |
Mon, 23 November 2015 09:06  |
 |
blyzz
Messages: 10 Registered: October 2015
|
Junior Member |
|
|
I need the function to get first and last day of the13 month back from the current month in Oracle.
Ex if the current month is Nov, I want first and last day for Oct 2014 and next month, it should be first and last day of Nov 2014.
How can I do that?
Thanks,
Blyzz
|
|
|
|
|
|
|
|
|
|
|
|
| Re: How to get first and last day for 13 month back [message #645011 is a reply to message #645007] |
Mon, 23 November 2015 09:30   |
Solomon Yakobson
Messages: 3312 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Actually, no need for LAST_DAY:
SQL> select trunc(add_months(sysdate,-14+level),'month') first_d,
2 trunc(add_months(sysdate,-13+level),'month') - 1 last_d
3 from dual
4 connect by level <= 14
5 /
FIRST_D LAST_D
------------------- -------------------
10/01/2014 00:00:00 10/31/2014 00:00:00
11/01/2014 00:00:00 11/30/2014 00:00:00
12/01/2014 00:00:00 12/31/2014 00:00:00
01/01/2015 00:00:00 01/31/2015 00:00:00
02/01/2015 00:00:00 02/28/2015 00:00:00
03/01/2015 00:00:00 03/31/2015 00:00:00
04/01/2015 00:00:00 04/30/2015 00:00:00
05/01/2015 00:00:00 05/31/2015 00:00:00
06/01/2015 00:00:00 06/30/2015 00:00:00
07/01/2015 00:00:00 07/31/2015 00:00:00
08/01/2015 00:00:00 08/31/2015 00:00:00
FIRST_D LAST_D
------------------- -------------------
09/01/2015 00:00:00 09/30/2015 00:00:00
10/01/2015 00:00:00 10/31/2015 00:00:00
11/01/2015 00:00:00 11/30/2015 00:00:00
14 rows selected.
SQL>
SY.
|
|
|
|
|
|