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.)

Similar Messages

  • What is the best way to add a day to a Date object?

    I have come across numerous examples on adding a day to the CURRENT date, using the Calendar object. However, what I need to do is to add a day to a Date variable.
    Can someone tell me how to do that? I tried to set the value of my Date variable into the Calendar object, but, it appears that for the current JAVA version, they have deprecated the getYear(), getMonth() and getDay() methods for the Date class.
    Really appreciate your suggestions.
    Thank you in advance,
    SiowLing

    I haven't seen the OP express a concern over how to create/obtain the Date object (he could be using "new Date()" given the emphasis on "CURRENT"). Milliseconds is fine too if that's what you have (for example from a java.sql.Date).
    So the way to add a day to a Date object (the OPs original question) is to:
    - set the Date on a Calendar using setTime
    - add 1 to the DATE field of the calendar
    - get the Date from the Calendar using getTime
    Obviously you're right if the OP doesn't have Date object to start with, but just the "numbers" for year, month, day.

  • 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

  • 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.

  • 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.

  • 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

  • How To Add Days into a Date from java.util.Date class

    I have a problem when i wants to add 2 or days into a
    date object geting by java.util.Date class. so please help me resolve this issue?
    for e.g i have a date object having 30/06/2001,
    by adding 2 days i want 02/07/2001 date object ?
    Code
    public class test2
    public static void main(String args[])
    java.util.Date postDate = new java.util.Date();
    myNewDate = postDate /* ?*/;
    Here i want to add 2 date into postDate

    Use Calendar...
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DAY, 2); // I'm not sure about that "DAY"

  • How can I add [# of days] to a date?

    edit::  Nevermind, I found the answer.  I'm using AS 2.0
    Answer: new Date(year, month, date+#)  where # is the # of days to add.
    Helpful link: http://blog.flexexamples.com/2007/08/24/date-math-for-lazy-people/  (AS 2.0 & 3.0)
    Original question:
    The title is horrible, couldn't think of how to word it.
    Anyway, I want to know how I can take a date, add a few days to it, then display the resulting date.
    For example, today's date is 8/20/2010.  I want to be able to add 10 days to this and then display the result in a label or other output.
    The label would then read 8/30/2010.  If I wanted to add 15 days to today's date, the label would read 9/4/2010.
    Any help is appreciated, thanks!

    Another way of adding values to a date object is to set up constants, and this will make life easier if you do Date math frequently, or are adding to a date which is unknown until runtime (i.e., not neccessarily today's date).
                private var todayDate:Date = new Date();
                //One day, in milliseconds:
                private const oneDay:Number = 1000 * 60 * 60 * 24;
                private function addDaysToTheDate():void {
                    //The number of days you wish to add:
                    var daysToAdd:Number = oneDay * 10;
                    //Add the days to today's date:
                    var answer:Date = new Date(todayDate.time + daysToAdd);
                    Alert.show(answer.toDateString());

  • How to add one day to a Date?

    Hi,
    What is the simplest way to daa one day to a Date object?
    Thanks.
    Pengyou

    You use a database query just to add one day
    to a Date object? I wouldn't call that the "simplest"
    way at all.I was going to suggest firing off an email to the naval observatory and having them carry out the calculation, emailing the result back (maybe using JMS, not sure - web service possibly?) but the OP's way is simpler.

  • Reusing Human Tasks across BPM Processes with different Data Objects

    Hi
    JDeveloper 11.1.1.6, WLS 10.3.6, SOA/BPM 11.1.1.6
    I have defined 2 BPM Processes, P1 and P2, which has 2 different Process Data Objects O1 and O2.
    But I am reusing the same Human Task in both the processes.
    For the Human Task to support the activities in both the processes, I have added O1 and O2 Data Objects in the Human Task Definition.
    And hence the ADF Taskflow / page generated out of the Human Task will have both the Data Objects O1 and O2 as payload objects in the Page.
    When an instance of Process P1 is created, the payload O1 will have values, but O2 will be null.
    And when an instance of Process P2 is created, the payload O2 will have values, but O1 will be null.
    It works well like this, but I am a bit concerned about the performance from BPM Process and also ADF page.
    In ADF page, let us say, somehow I can control the rendering of the attributes or creation of the iterator bindings based on identifying which process is being executed.
    (By setting the iterator binding refresh property in page definition)
    In this way attribute bindings for O1 will not be created when P2 is being executed.
    But still when the Process instance is created, and when we see the payload structure of the human task in the EM - Audit Trail,
    I still see both data objects O1 and O2 are created in the Payload, but O1 will have nulls in process P2.
    So my question is, from performance point of view, is it advisable to define different Data Objects in reusable Human tasks ?
    Or should I have to define a separate Human Task definition which contains only the Data Objects related to the process it is being called from ?
    Thanks for any help
    Sameer 

    Martijn,
    You are correct in your assessment that the JAG in the current JHeadstart release cannot cope with multiple bc4j packages. There is no work around for this. Upgrading to 9051 will not help.
    In the JHeadstart-ADF release, this restriction has been lifted. You can place your EO, VO and AM objects in different packages, and you can group them in a separate project (Model project), while generating your JHeadstart application in a ViewController project.
    We have a number of customers that use the latest JHeadstart-ADF builds to build their ADF apps. If you are interested in joining this beta program, please send an e-mail to [email protected]
    Steven Davelaar,
    JHeadstart Team.

  • Get Date x number of days before current Date

    How do you subtract x number of days from a Date object?
    Is there a better way than
    int x = 28; // number of days
    long minisPerDay = 24 * 60 * 60 * 1000;
    Date newDate = new Date (oldDate.getTime() - (x * minisPerDay );

    > How do you subtract x number of days from a Date object?
    Calendar c = Calendar.getInstance();
    c.setTime(yourDateInstance);
    c.add(Calendar.DATE, -x);
    Calculating Java dates: Take the time to learn how to create and use dates
    Working in Java time: Learn the basics of calculating elapsed time in Java
    Good luck! :o)
    ~

  • Adding an "x" number of Days to Date Object

    Hi guys,
    What I would like to is lets say you have a date object, looking for method/way of adding or subtracting X amount of days from that object.
    This is because I have a list of dates that I would like to follow up on eachother like :
    1/7/06-5/7/06(Date EndDate)
    (Date EndDate + 1) i.e 2/7/06 - 31/7/06
    Thanks in advance

    For anyone that has the same problem this is how I got it working.
    Thanks for the help in the post.
         static Date addDaysToDate(Date startMonth, int days)
              Calendar c = Calendar.getInstance();
              c.setTime(startMonth);
              c.add(Calendar.DATE, days);
              startMonth = c.getTime();
              return startMonth;
         }

Maybe you are looking for

  • Problem invoking webservice on weblogic managed server

    Hi Guys, I've created a web service using examples the BEA provides. When I deploy my web service on a ADMIN server it works fine. When I depoly my web service on a managed server, my client cannot find the WSDL file suppose to be located on the a ma

  • MacBook to TV...audio not working

    I have an HDMI cable which works just fine for delivering video from my pre-2008 MacBook Pro to my TV.  However, I don't have any audio.  I tried a separate optical cable but that didn't work.  Any suggestions?  Thanks!!!!

  • Upgrading Hard drive & RAM

    Hi,  I own a HP dv7-3085dx (product no : VM188UA#ABA) and I need to upgrade my hard drive to a SSD & upgrade my RAM. currenlty I'm having 500GB hdd & 6144MB DDR3 ram.  1. Please let me know whether Serial ATA III SSD (Samsung - 840 EVO 250GB Internal

  • Converting Planned Order to Purchase Requisition

    Is their configuration that can automatically convert planned order to purchase requisition based on information like planned delivery time, etc.?  Or, does the conversion of planned order have to be done via MD15 either manually or by batch job?

  • Problem with Oracle Native Sequencing - please help!!

    Hello I am migrating from 3.6.5 to 10.1.3.1 (huge jump). And have a problem with sequencing. When I create new object Toplink does not pick up Sequence object name from the descriptor. When I see generated SQL it shows: SELECT .NEXTVAL FROM DUAL Each