I want a function in Oracle such as this.

After i giving a parameter an easy date. Then function should getting me last day's the prior month.


FunctionName(10.02.2011) Result should be 31.01.2011

FunctionName(21.03.2011) Result should be 28.02.2011

FunctionName(31.07.2011) Result should be 30.06.2011 (Even date is last day of month)

How do i do this? Incidentally, i never use Oracle .

You can test this (a minimum of for version 11.1, i am unsure this functions is available on previous versions).


Instead of another solutions here, there are also the final day's the prior month through getting yesterday the very first day of the month

SELECT trunc(your_date, 'MM')-1 as new_date from your_table

I'd most likely still recommend using last_day(add_months(xxx,-1)) but simply showing an alternate.

select LAST_DAY(ADD_MONTHS(sysdate, -1)) from dual

format resulting date as you desire (I'll leave that certain for you personally )