Solved

Need to get the last day of the month (Dec 31) for 2012 not 2013?

Posted on 2014-01-17
3
427 Views
Last Modified: 2014-01-17
Hello, I'm trying to get the last day of the month for the prior year 2012 instead of 2013.

Thanks

Example

select * from hsp_bkt_aging_hx

where hsp_bkt_aging_hx.aging_date =  LAST_DAY(ADD_MONTHS(TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year'),11))
0
Comment
Question by:MIREESE
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
trunc(sysdate,'yyyy') -1

will return Dec 31 2013


add_months(trunc(sysdate,'yyyy') -1,-12)

will return Dec 31 2012

you could also use

trunc(trunc(sysdate,'yyyy')-1,'yyyy')-1
or
trunc(sysdate,'yyyy') - 1  - interval '1' year
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
To get the last day of the year before last -
select add_months(trunc(sysdate,'yy') - 1,-12) from dual;
Can you provide a little more description of what you need given different current dates?
0
 

Author Closing Comment

by:MIREESE
Comment Utility
Thanks This worked!!


Since this is only an issue in January, How could I code this to look back 2 years only during January and only look back 1 year the after January?

Example

If Month = Jan aging date = last month of 2012 else

LAST_DAY(ADD_MONTHS(TRUNC(TRUNC(SYSDATE , 'Year')-1 , 'Year'),11))  /*2013*/
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now