Adding days to a date causes it to be set back a year.

Hello,
I have the following problem on Oracle 10g. I run the following statment that adds 1 year to a date but, unless I format it, the date comes back with one year less than it should.
SQL> select effective_date, (effective_date + interval '1' year(1)) as addyear, add_months(to_date(to_char(effective_date, 'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'), 12) as addyearformat
   from price_change
        where
        price_change_id = '794328'   ;
EFFECTIVE_DATE  ADDYEAR         ADDYEARFORMAT
28-SEP-09       28-SEP-08       28-SEP-10Has anyone else ever seen something like this?
Effective_date is a date type and has data in the format 'MM/DD/YYYY HH24:MI:SS'. I think it is something with the format, maybe something to do with the time zone - not sure. If I just insert a value into the table with the format 'MM/DD/YYYY HH24:MI:SS' I don't have this problem. I don't know how the date could have been changed to cause this but I do know it goes through a time zone function before being inserted into this table though I don't know if that is causing the problem.
Not sure if it matters but nls_database_parameters...
PARAMETER VALUE
NLS_DATE_FORMAT dd-mon-rr
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
Thanks for any help in advance.
Edited by: amcgator on Oct 15, 2010 11:52 AM

Funny, but I think somehow your dates are BC:
with price_change as (
                      select to_date('28-SEP-09 BC','dd-mon-yy bc') effective_date from dual
select  effective_date,
        (effective_date + interval '1' year(1)) as addyear,
        add_months(to_date(to_char(effective_date, 'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS'), 12) as addyearformat
  from  price_change
EFFECTIVE ADDYEAR   ADDYEARFO
28-SEP-09 28-SEP-08 28-SEP-10
SQL> Issue:
select  to_char(effective_date,'mm/dd/yyyy bc')
  from  price_change
  where price_change_id = '794328'
/SY.

Similar Messages

  • Adding days to a date

    Hi, i've been trying to add days to a date with no luck.
    I have two dates.
    Date date1= new Date();
    Date date2;
    I want date2 to equal x amount of days from date1.
    eg. date1 = 6/10/2004
    I want date2 to be 4 days from date1 so date2 would be 10/10/2004. i know this is very easy to do with the Calendar class but in my program it needs to be a Date because i parse Strings (dd/mm/yyyy) to Dates. It is not possible to parse Strings to Calendar date's right?
    So if anyone can help me add days to a Date object, it would be great!
    Thanks

    >
    testParse.java:33: 'void' type not allowed here
    System.out.println (testDate2.setTime(newTime));You are trying to print out the results of the void
    method, i.e. a void, not the object.
    d-unknown, if you look closely at the error message provided and the line it's complaining about, and use a little process of elimination, I think you'll find that there are only so many possibilities as to what possibly could be wrong.
    These compiler errors are not cryptic curses thrown up to stop people from getting work done, the counterspells to which are only known to those who have been through the rite of passage and had a coffee cup branded on their butts. The error messages are your friends. They tell you pretty precisely what went wrong and where if you take the time and effort to read an understand them.
    "'void' type not allowed here" -- Where have you ever seen the word void when programming Java? As the return type of a method, right? So, "'void' type" is probaby talking about the return type of some method.
    "not allowed here" -- well, it looks like you're doing something with a void where you can't have a void.
    There are only two method calls on that line--println and setTime. Both return void, so either one could be the problem. Either one might be being used where it's not allowed.
    But wait, what could possibly be wrong with where you're using println? It's just like every other println you've ever used.
    What about setTime? Well, println has several signatures. One takes object, and there's one for int, float, etc. So what you pass to println has to be one of those types. Is the return type of setTime an Object or int or long or anything? No, it's void. It's nothing. It has no value. println needs a value, but you're passing something that has no value. It would be like saying x=date2.setTime(...) It makes no sense, because a method with a void return type doesn't return any value.
    See, that wasn't so hard, was it? Yeah, it was wordy, but really if you start with "what could be void in this line and how could it be causing a problem," the thought process only has a few steps to get to the answer.

  • XQuery function : Adding day to current date

    I have a requirement to add 1 day to the current date during the Xquery transformation.
    Does anyone know if there is any xquery function that does that?
    From this link,
    http://download.oracle.com/docs/cd/E13214_01/wli/docs92/xref/xqdtopref.html#wp1162860
    it seems like there is a function, op: add-yearMonthDuration-to-dateTime, that serve this purpose, but I don't find it in OSB console IDE nor OEPE.

    You can use the below expression for adding 1 day (24 hrs) to a given current date:
    fn:current-dateTime() + xdt:dayTimeDuration("PT24H")
    Thanks,
    Patrick

  • Adding days to a date object

    I am retreiving a date field from the database.
    i am retrieving that with getDate() method on the result set object.
    that is am retrieving as java.sql.Date object.
    on that date object i have to add 30 days and store it back in the
    database as a date field in database.
    How should i go about handling this problem.
    suppose
    java.sql.Date newDate=rs.getDate(1);
    on this newDate how can i add 30 days and store it back to the database.
    Plz help me out guyz.
    Thanks.

    wud the setting to a particuale date means setting to
    the date i retrieved from the database.
    How to set for a particular date.We have setTime()
    method in Calendar.
    but that takes util.Date object.Then do i have to
    convert the sql.Date object into a util.Date object.A java.sql.Date IS-A java.util.Date.
    (There's no such thing as a sql.Date or a util.Date unless you have a different API than the rest of us.)

  • Need help in adding days to a date

    Hi,
    In rtf when if condition is true I have to add 7 days for a particular date.
    I am using logic like this <?xdofx:DATE+07?>
    but it is giving output like if :date is 27-FEB-08 then it is showing output like 2715
    I also checked like this
    case1:<?xdoxslt:ora_format_date_offset(DATE,'7', ‘+’)?>
    case2: <?xdofx:round((to_number(to_char(DUN_DATE,'JSSSSS'))+to_number(to_char(to_date('07','YYYY-MM-DD'),'JSSSSS'))) div 100000)?>
    Still not working.
    Please help me how to do this?
    Thanks in advance

    you should use these functions
    <?xdoxslt:ora_format_date_offset(xdoxslt:sysdate(),2,’+’)?>
    <?xdoxslt:ora_format_date_offset(yourdate, offset or days, ‘operator + - ’)?>
    i guess , something better will come in future , when the xsl 2.0, is being supported here in bip

  • Adding days to the date field

    Hi,
    I have a scenario as below.
    I have to add no. of days to the exixsting date field in the program. The statement is like this.
               <b>DATE1 = DATE + XDAYS.</b>
    Where <b>DATE</b> is in <b>DDMMYYYY</b> format. and XDAYS holds the number of days which will be retrieved from the standard table. And DATE1 should hold the result date.
    <b>eg:</b> Let <b>DATE</b> = <b>30.08.2007</b>
               <b>XDAYS</b> = <b>15</b>
    DATE1 = DATE + XDAYS.   =>   <b>DATE1 = 30.08.2007 + 15</b>.
    <b>DATE1 = 14.09.2007</b>
    Is there any easiest way to do this. or is there any function mdule  to do this operation.
    I hope you understood the question. Please let me know if I need to be more clear.
    Thanks in advance.
    -Pradeep.

    Hi,
    The date will be in internal format of 8 digits... Like 20070830..
    Directly add the number of days.. system will automatcally calculate
    w_new = w_old + 15 (20070830 + 15)
    w_new becomes 20070914
    and when you will write this : WRITE : w_new. It will show 14.09.2007 or depending on your settings for the date format. No need to call any fm for this..
    Thanks and Best Regards,
    Vikas Bittera.
    **Reward if useful**

  • Adding days in prompt date

    Hi Guys
    I need to create the filter like:-
    user select the date using the prompt on report while opening the report and i need to use the date entered by user which will be compared as
    date > user_Selected_dt +14 days..
    i have created the prompt and in report i can see the date selected by user using UserResponse () function but how to put same in filter.
    regards

    Just create a formula in Webi, let's say "Date Filter" =
    if date > user_Selected_dt +14 days then "filtered rows" else "Display All"
    No you can use the 'Date Filter" in interactive filter or table filters or controls.

  • Leap year bug adding days to a date?

    Please try this xquery:
    <dd>
    for $i in 0 to 4
    return
    <d>
    {xs:date('2008-12-29')+xs:dayTimeDuration(concat('P',$i,'D'))     }
    </d>
    </dd>
    If the starting date is a leap year date (eg: 2008-12-29), the result does not contain the 30rd of december!
    Is this a (known) bug or there is something wrong in my xquery?
    Thanks!
    Bye
    Mirko

    Hi Mirko,
    There's nothing wrong with your query - that looks like a bug in our date displaying code. Thanks for your analysis of the problem - I'll take a look into fixing it.
    John

  • Adding 1 day to a date in BPEL

    Hi,
    Im trying to add 1 day to a date in a BPEL proces. I saw that there was a xp20:add-dayTimeDuration-to-dateTime so I tried using this in several ways. I didnt expect the input variable to be a string. I tried converting my date to a string and adding 1 day like this:
    xp20:add-dayTimeDuration-to-dateTime(xp20:format-dateTime(string(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum')), 'YYYY-MM-DD'), 'P1D')
    But the variables which I try to fill stays empty. The element which I try to fill is of type dateTime. Is this maybe the error that add-dayTimeDuration-to-dateTime returns a string and it cannot cast it to dateTime?
    Can anyone tell me how to solve this properly?
    Thanks in advance!

    Hi,
    I refactored my expression to look like this:
    xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum'), 'P1D'), '[Y]-[M]-[D]')
    But the I receive an error: XMLElement cannot be cast to java.lang.String
    Then I tried:
    xp20:format-dateTime(string(xp20:add-dayTimeDuration-to-dateTime(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum')), 'P1D'), '[Y]-[M]-[D]')
    Because xp20:add-dayTimeDuration-to-dateTime needs a String as input and I dont know how getVariableData returned it but with this I get the error:Parse Error in string function
    Any ideas?

  • Adding days to the current date

    I'm trying to write a program that takes an order and prints an invoice for my intro to java class. The date of the order and the date of arrival (which is 14 days after the date of the order) are to appear on this invoice. I thought that I figured it out but I get a compile error. Here's what I have so far:
    SimpleDateFormat formatDate = new SimpleDateFormat("MMMMM, dd, yyyy");
        Calendar rightNow = Calendar.getInstance();
        public String dateOfOrder()
             return formatDate.format(rightNow);
        public String dateOfArrival()
             return formatDate.format(rightNow.add(DAY_OF_MONTH, 14));
        }I'm writing it in JCreator and I get "cannot find symbol variable DAY_OF_MONTH" as my compile error. It compiled just fine until I added the dateOfArrival method. I keep reading through the Calendar API but I just can't understand why it won't work. What am I doing wrong?

    masijade. wrote:
    Which class is "DAY_OF_MONTH" a part of (I know what it is, but I want you to think on it). Try adding that class name to the front of the field name, with a period between them i.e.Calendar?
    I tried making the following adjustment but just got a new error.
    public String dateOfArrival()
             return formatDate.format(rightNow.add(Calendar.DAY_OF_MONTH, 14));
        }My error this time is: 'void' type not allowed here
    It seems like it is recognizing DAY_OF_MONTH now but something else is going wrong. Where am I going wrong?

  • Adding days of date

    Dear all
    Using form6i and run in c\s
    is it possible to add days of date.. example the format of date is 02-mar-07
    in text item i enter 3 then the date will become 05-mar-07. it depends what number will be entered in textitem and it will add to the days of date..
    |Another example is: date format is 29-mar-07.. i entered 4 in textitem the date will become 02-apr-07 ...
    Could anyone help me to do this or is there any ideas must simplest than this that can add a days of a date plz help me need in school requirements...

    Say, you have two items
    b_day.txt_refdate - the refernce date.
    b_day.txt_inc - the number which should b added.
    b_day.txt_result - to store the result.
    in WHEN-VALIDATE-ITEM of b_day.txt_inc, write
    begin
    b_day.txt_result := to_date(b_day.txt_refdate + b_day.txt_inc,'dd-mon-rrrr');
    end;

  • Adding hours/day to a date

    Hello,
    I have field of length 20 which contains date in the format “mm/dd/yyyy hh:mm:ss”.
    I want to add 5 hrs, 8 hrs, 2 days to this date value depending upon some condition.
    Can anyone please suggest how to do this or any FM which does this.
    Thanks in advance

    Hi..
    DATA : FA(20) TYPE c,
           FB(10) TYPE c,
           FC     TYPE d,
           FD(8)  TYPE c,
           FE     TYPE t.
    data : f_m(10) type c,
           f_d(10) type c,
           f_y(10) type c,
           f_h(10) type c,
           f_mi(10) type c,
           f_s(10)  type c,
           f_aa(10) type c,
           f_bb(10) type c.
    FA = '07/01/2007 08:09:10'.
    SPLIT fa AT space INTO f_aa f_bb.
    SPLIT f_aa AT '/' INTO f_m f_d f_y.
    SPLIT f_bb AT ':' INTO f_h f_mi f_s.
    add your logic...
    i want to help you.
    regards..

  • Adding Business Days to a Date

    Hi everyone,
    I'm trying to add a certain number of working days to  a date,what I am hoping to get is a date excluding the weekends
    For example:
    If i was to add 12 working days to 01/05/2009 i should get 19/05/2009
    Thank You
    MT

    Mistook 01/05/2009 as Jan 5th and was wondering why your statements contradicted.  I see you mean May 1st.
    Try a formula such as this:
    numbervar i := 1;
    datevar c := date(#05/01/2009#);
    numbervar z := 12;
    datetimevar k := date(0,0,0);
    while i <= z do
    k := dateadd('d',i,c);
    (if dayofweek(k) in [1, 7] then
    (z := z + 1;)
    k := date(0,0,0);
    i := i +1;
    dateadd('d',z,c);
    where 'C' is the starting date and 'Z' is the number of working days.

  • PL/SQL Function: Adding Days to Date

    I have a function that adds a given number of days to a date, and excludes Saturday, Sunday, or Monday if needed with parameters. The problem is when the given date is a Friday, you need to add one day, and you exclude Saturday and Sunday i.e. DAYSBETWEEN('30-SEP-11',1,1,1,0) or DAYSBETWEEN('30-SEP-11',1,1,1,1).
    Where am I going wrong here and what needs to be fixed?
    create or replace
    FUNCTION daysbetween(
          DAYIN  IN DATE ,
          ADDNUM IN NUMBER ,
          EXSAT  IN NUMBER ,
          EXSUN  IN NUMBER ,
          EXMON  IN NUMBER )
        RETURN DATE
      IS
        dtestart DATE;
        dteend Date;
        intcount NUMBER;
      BEGIN
      WITH all_dates AS
        (SELECT LEVEL AS days_to_add ,
          dayin ,
          dayin + LEVEL AS new_dt ,
          addnum ,
          exsat ,
          exsun ,
          exmon
        FROM dual
          CONNECT BY LEVEL <= addnum * 2
        exclusions AS
        (SELECT ROW_NUMBER() OVER ( ORDER BY new_dt) ordering ,
          addnum ,
          new_dt ,
          TO_CHAR ( new_dt, 'DY' )
        FROM all_dates
        WHERE 1                       =1
        AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exsat, 1, 'SAT', 'XXX')
        AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exsun, 1, 'SUN', 'XXX')
        AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exmon, 1, 'MON', 'XXX')
      SELECT MAX( new_dt ) INTO dteend FROM exclusions WHERE ordering <= addnum;
      RETURN dteend;
    END daysbetween;

    You could do something in SQL like this perhaps...
    SQL> ed
    Wrote file afiedt.buf
      1  with x as (select rownum as days_to_add from dual connect by rownum <= 31)
      2      ,y as (select sysdate as dt from dual)
      3  --
      4  -- end of test data
      5  --
      6  select dt, days_to_add
      7        ,case when to_char(new_dt,'fmDAY') IN ('SATURDAY','SUNDAY') then new_dt + 2
      8         else new_dt
      9         end as new_dt
    10  from (
    11        select dt
    12              ,days_to_add
    13              ,dt
    14               +floor(days_to_add/5)*7
    15               +mod(days_to_add,5) as new_dt
    16        from x,y
    17*      )
    SQL> /
    DT                   DAYS_TO_ADD NEW_DT
    05-OCT-2011 16:33:27           1 06-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           2 07-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           3 10-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           4 11-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           5 12-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           6 13-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           7 14-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           8 17-OCT-2011 16:33:27
    05-OCT-2011 16:33:27           9 18-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          10 19-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          11 20-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          12 21-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          13 24-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          14 25-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          15 26-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          16 27-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          17 28-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          18 31-OCT-2011 16:33:27
    05-OCT-2011 16:33:27          19 01-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          20 02-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          21 03-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          22 04-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          23 07-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          24 08-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          25 09-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          26 10-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          27 11-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          28 14-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          29 15-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          30 16-NOV-2011 16:33:27
    05-OCT-2011 16:33:27          31 17-NOV-2011 16:33:27
    31 rows selected.

  • Strange one day adding to tasks due date (Outlook –SharePoint- MS Project integration)

    Hi,
    I have integrated MS Project 2010 with MS Outlook 2010 via SharePoint. Everything has gone more or less smoothly (as it could be for Microsoft
    J), but finally I got into a strange problem. Strangely enough,
    MS Outlook, while syncing tasks with SharePoint (these tasks are pre-created in MS Project and synced with SharePoint beforehand),
    adds one day to due dates of each of these tasks, e.g. for “Task 1” due date in MS Project and on SharePoint is 20.10.2010, but MS Outlook puts it as 21.10.2010, for “Task 2” due date in MS Project and on SharePoint is 22.10.2010, but MS Outlook
    puts it as 23.10.2010, etc.
    What is a strange trick? I have checked work time, holidays - everything is the same in MS Outlook, SharePoint and MS Project (8-17, Mon-Fri, 8 hours, 40 days a week). What could it be?
    Thanks a lot.

    Hi,
    It seems nobody can reply, so I will reply by myself because I found out the answer. The answer from Microsoft is pretty simple - ha-ha we know about,
    we will work on it, wait, ha-ha. Firstly let me quote Microsoft senior tech answer on the same request 3 month ago:
    "Hello Artur,
    The senior tech got back to me with the following conclusion:
    Outlook is rounding everything set to 12:00 PM or after to the next date because the columns mapped to start date and due dates are only Date columns,
    not date/time columns.
    It is rounding at noon because of the .5 decimal. This can be seen in Excel - 41115.5 = 7/25/2012 12:00 in date/time format whereas 41115.49 = 7/25/2012
    11:45.
    The issue seems to be an expected behavior, the next level of support is working on the same but currently I have not been provided with any ETA, so
    it looks like the issue will take a good amount of time to get fixed.
    I would appreciate your patience while we are working on the issue. I will keep you posted as and when I get an update on the issue."
    Sounds good, does not it? Ok. After asking this question recently I got run-around and finally I found the same question unsolved (see the quotation
    before) more than 3 month ago. I have sent it to Microsoft Tech Support. Look at reply I got from them on 22.10.2012:
    "This issue has been noticed and will be handled by the product team. Once we have any updates, it will be responded to you timely". 
    So the basic function does not work properly, there month passed - no way! Wait until what? I could hardly
    even imagine how Microsoft launched the product with such a bug and is not resolving the problem for months.

Maybe you are looking for

  • Error Deploying HelloWorldBPELProcess

    Hi I am just getting started with SOA suite I have installed following Version details JDeveloper 11.1.1.2.0 WebLogic Server (10.3.2) SOA Suite (11.1.1.2.0) Now trying to deploy HelloWorldBPELProcess (composite) but during deploy from Jdev so followe

  • Disk Utility - minimum diskimage size

    Folks; Using Leopard's Disk Utility, I want to make a disk image for a particular file and size the image to be the minimum required for my ~6.5M file. I create a new image (20M), because a 10M tells me that there is only 1.7M free and won't let me c

  • Know about ant-sca-deploy.xml

    Hi All, Can you please explain me the ant-sca-deploy.xml works, whcih parameters has to be passed ? for deployment

  • Camera is not working with fring

    hii friend pls help me.i'm using nokia 701 .i'm not abal to do video calling through "fring software ".... Moderator's note: We changed the title to a more topic-related subject as the post was moved to the appropriate board. 

  • Upgrading script from 4.6 to 5.0

    hi all, please help me with procedure to upgrade script from 4.6c to ecc 5.0. reply ASAP. thanks in advance . pavani.