Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-17
3
Medium Priority
?
433 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

730 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