Getting Last Day of Previous Month in Oracle Function

Soner Gönül picture Soner Gönül · Feb 10, 2011 · Viewed 65.8k times · Source

I need a function in Oracle like this.

When i giving a parameter a simple date. Then function should getting me last day of the previous month.

Example:

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 can i do that? By the way, i never use Oracle .

Answer

Lamak picture Lamak · Feb 10, 2011
SELECT LAST_DAY(ADD_MONTHS(yourdate,-1))