22 Ocak 2016 Cuma

Oracle Finding first day of the month

Hi

Following sql helps you to find first day of previous months.


select  trunc(sysdate) from dual

22.01.2016

First Day of Current Month:
select    ADD_MONTHS (   LAST_DAY (  TRUNC (SYSDATE)  )  ,   -1  )+1   from dual

01.01.2016                                                                    

First Day of  eleven months before:                                      
select    ADD_MONTHS (   LAST_DAY (  TRUNC (SYSDATE)  )  ,   -11  )+1   from dual

01.03.2015

21 Ocak 2016 Perşembe

Oracle Finding Last_Day of Previous months

Hi

Following sql helps you to get previous months  last_day values:

Current Date:
select  trunc(sysdate) from dual
22.01.2016

Results:
-- One month before
select   ADD_MONTHS (LAST_DAY (TRUNC (SYSDATE)),-1)   from dual
31.12.2015

-- Eleven months before
select   ADD_MONTHS (LAST_DAY (TRUNC (SYSDATE)),-11)   from dual
28.02.2015