Solved

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

Posted on 2014-01-17
3
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39788944
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 32

Expert Comment

by:awking00
ID: 39788960
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
ID: 39788980
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

752 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