PL/SQL (MOSC)

MOSC Banner

Get Last date of every Month in a year

edited Jan 9, 2014 8:12PM in PL/SQL (MOSC) 12 commentsAnswered ✓
 Hi All, 

I need to find last date of month for given year.

Example:

 

I used to pass date or year such as 2012 or 01-01-2012(DD-MM-YYYY)

 

SQL query needs to return last date of every month such as

 

31-01-2012

28-02-2012

31-03-2012

30-04-2012

.

.

.

.

.

31-12-2012

 

for above requirement i have written the following SQL

 

  1. select rownum as row_count,  
  2. case when rownum=1 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as Jan_month,  
  3. case when rownum=2 then last_day(to_date(add_months(trunc(to_date('01-01-2014','DD-MM-YYYY'), 'YYYY'), level - 1), 'DD-MM-YY')) end as Feb_month,  

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center