How can I add days to a date?

I need to find a way to add days to a date. For example, today is 10/3/03 and I want to add 180 days to that. How do I do that? Here is my code so far....
import java.util.*;
import java.text.*;
public class Loan
     String date;
     String loanEndDate;
     public void setDate()
GregorianCalendar gregNow = new GregorianCalendar();
Date now = gregNow.getTime();
DateFormat shortDate = DateFormat.getDateInstance(DateFormat.SHORT);
date = shortDate.format(now);
public String getDate()
return date;
public void printLoanBegDate()
          System.out.println("Loan Beg Date: " + date);
     public String setLoanEndDate()
          loanEndDate = (getDate() + 180);
          return loanEndDate;
     public void printLoanEndDate()
          System.out.println("Loan End Date: " + loanEndDate);
The output is displayed by the following program:
public class DemoLoan
     public static void main(String[] args) throws Exception
     Loan anLoan = new Loan();
     anLoan.setDate();
     anLoan.printLoanBegDate();
     anLoan.setLoanEndDate();
     anLoan.printLoanEndDate();
The output is as follows:
10/4/03
10/4/03180 - - Why does this print the 180 afterwards? How can I get that to display the date 180 days into the future??
Thanks

Re: storing your dates as Dates, I mean don't have a field in your class called "date" which is a String. Have a field in your class called "date" which is a Date. If one aspect of your class is a moment in time, then use the java class that best represents a moment in time: java.util.Date. Don't make things more complicated than they have to be.
Re: adding, it's in the docs:
http://java.sun.com/j2se/1.4.1/docs/api/java/util/Calendar.html
and
http://java.sun.com/j2se/1.4.1/docs/api/java/util/GregorianCalendar.html
But anyway it's like:
Calendar c = new GregorianCalendar(); // now
c.add(Calendar.DATE, 180); // 180 days from now
Date nowPlus180 = c.getTime();
DateFormat shortDate = DateFormat.getDateInstance(DateFormat.SHORT);
System.out.println(shortDate.format(nowPlus180));

Similar Messages

  • How can i add the dimensions and data loading into planning apllications?

    Now please let me know how can i add the dimensions and data loading into planning apllication without manuallly?

    you can use tools like ODI or DIM or HAL to load metadata & data into planning applications.
    The data load can be done at the Essbase end using rules file. But metadata changes should flow from planning to essbase through any of above mentioned tools and also there are many other way to achieve the same.
    - Krish

  • How can i add formula to waveform data type?

    I want to interpolate my acquired data in terms of voltage to temperature. For this i need to use polynomial equation, but i am not able to directly attach formula node to the waveform data type. I want to know how can i add formula node to waveform data, and then also have it real time.

    One additional thought that may be helpful. Once you get the Y component of the waveform graph you are going to attempt to wire this into a formula node. You can do one of two things with that array. Put a for loop around the formula node and index the array into and out of the for loop. This allows you to do scalar math on the data. It is also possible to index and array in a formula node. The following KnoledgeBase demonstrates how to do this: http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/9d72b6069346942386256a0d00604ed4?OpenDocument

  • How do I add days to a date in Numbers?

    I want to build a chart that will add 151 days to a date. In Numbers 08 I used (date entered + 151) and it worked. How is it done with Numbers 09? I get an error that I can not compare dates and numbers

    e3farms,
    As far as I can see, with respect to your problem Numbers '09 works the same way as its predecessor. In the example below 100 is added to Jan 20, 2009, yielding the same result in each case.
    pw

  • Require a function module to add days to a date?

    My purpose is to add days to a particular date and get the resulting date. I tried using this function module "RP_CALC_DATE_IN_INTERVAL", but the problem is this function module only accepts two digits for days. i.e. i am only able to add a maximum of 99 days to a particular date, but i do want to go further and add more so please tell me if there is any function module which shall help me add 3 digit days to a date.

    Hi Kiran,
    You can directly add days to the date.
    Eg:
    DATA date LIKE sy-datum.
    DATA days TYPE i.
    date = sy-datum.
    days = 100.
    date = date + days.
    WRITE date.
    Regards
    Wenceslaus

  • How can I add the date at the top of the screen along with the day and time display?

    Hello,
    How can I add the date at the top of the screen along with the day and time display?
    Thanks so much!

    Open System Preferences>Date & Time:
    Ciao.

  • How i can add days to a date using sql

    Hi.
    Sorry the question, it's a very simple question, but i'm not finding the answer to that.
    I need some function that act just like the function add_months, but instead adding months, it need to add days to a date.
    I've used the function add_days once, but now, my select returns an error code when i try to use that function.
    My Oracle version is Oracle8 8.0.5.0.0
    runnig under Linux.
    Thanks,
    Klaus Paul

    To add days just do date arthmetic. Ex
    SQL> select sysdate+10 from dual;
    SYSDATE+1
    05-MAR-00
    add_days is a not Oracle date function.
    null

  • How can i add one month to a date variable ?

    Unlike the week which always 7 days, month may change from 28 to
    31, so how can i add one month to a date variable ? Thanks in
    advance.

    Adding 365 won't always work because of leap years.
    You could use the following SQL statement:
    SELECT
         TO_DATE(
              TO_CHAR(TO_DATE(SYSDATE), 'DD-MON-') ||
                (TO_CHAR(TO_DATE(SYSDATE), 'YYYY') + 1)) NEXT_YEAR
    FROM
         dual
    NEXT_YEAR
    08-JAN-03Or you could create your own function. You would use this
    exactly like add_months:
    CREATE OR REPLACE FUNCTION add_years
         (v_date DATE, num_years NUMBER)
    RETURN DATE AS
         v_year DATE;
    BEGIN
         v_year := TO_DATE(
                   TO_CHAR(TO_DATE(SYSDATE), 'DD-MON-') ||
                         (TO_CHAR(TO_DATE(SYSDATE), 'YYYY')
                                             + num_years));
         RETURN v_year;
    END;     
    SELECT
         add_years(SYSDATE, 1) new_year
    FROM
         dual
    NEW_YEAR 
    08-JAN-03
    SELECT
         add_years(SYSDATE, -1) new_year
    FROM
         dual
    NEW_YEAR 
    08-JAN-01

  • How can I add the expiration date at line item level

    My User is selling voucher. The voucher is sell at line item. eg GV$5, GV$10,etc
    Each voucher line item sold need to be entered with a EXPIRATION date of that voucher.
    Maybe 3 months from issue, maybe 6months/1 year from issue.
    How can I add this to the sales order line item level?
    Which field can I used and how to configure?

    Hi Colin ,
       The question is not very clear , but i assume that you are asking about the  self expiry date of the particular material ,
    1. The setting you can do by activating  shelf life data  in material master :Plant data/stor1
    2.  its better to have a batch managed material for that you can sort the material acording the self expiry date.
    3. Once you maintain self expiry date system by default pick  the material at the time of  delivery
    Note-Shelf life expiry it will give the life of the material from the day of manfacture,remaining shelf life also will  give .
    Hope it is helpful
    Best regards
    Venkat

  • How Can i add "DateDiff(day, T0.DueDate" as a column in this query?

    How Can i add "DateDiff(day, T0.DueDate" as a column in this query?
    SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
          CASE  WHEN T0.TransType=13 THEN 'Invoice'
               WHEN T0.TransType=14 THEN 'Credit Note'
               WHEN T0.TransType=30 THEN 'Journal'
               WHEN T0.TransType=24 THEN 'Receipt'
               END AS 'Document Type',
          T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
          ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
          ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
          ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
          ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
          ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
          ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
    FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    WHERE (T0.MthDate IS NULL OR T0.MthDate > [%1]) AND T0.RefDate <= [%1] AND T1.CardType = 'C'
    ORDER BY T1.CardCode, T0.DueDate, T0.Ref1

    Hi,
    As you mentioned not possible to assign the dynamic column in the query.
    will give you example for generate a dynamic column name in SQL query, using this example you can achieve your requirement.
    DECLARE @cols AS NVARCHAR(MAX),
        @query  AS NVARCHAR(MAX)
    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(C.Name) 
                        from [History]
                FOR XML PATH(''), TYPE
                ).value('.', 'NVARCHAR(MAX)')
            ,1,1,'')
    set @query = 'SELECT [Date],' + @cols +'
                 from
                    select [Date], Name, Value
                    from [History]
                 ) x
                pivot
                    max(value)
                    for Name in (' + @cols + ')
                ) p '
    execute(@query)

  • I got the new iPhone 5C. In my cellular settings, under "Use cellular data for", it only show passbook and facetime. How can I add other apps? Also, my carrier is AT&T

    I got the new iPhone 5C. In my cellular settings, under "Use cellular data for", it only show passbook and facetime. How can I add other apps? Also, my carrier is AT&amp;T

    Hello Sophie59
    You should be able to see two different tabs when setting up the email if you go to Other > Add Mail Account. Once you enter in the email address and password, you should be at the next screen to provide more details about the email as far as incoming and outgoing servers and at the top there will be a blue section to add it in as a POP or IMAP email account. Check out the article below for further troubleshooting and emails setup options.
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    iOS: Adding an email account
    http://support.apple.com/kb/ht4810
    Regards,
    -Norm G.

  • How can I add date to photos taken on my iphone 4s

    How can I add a date to photos taken on my iphone 4s?

    That's correct - Photos supports geotagging, but only allows viewing of that information. Once an image is in Photos, geotags cannot be added, deleted, or edited. This post suggests some apps for editing geotags outside of the Photos app. As you mentioned, you can edit the geotags in iPhoto, export to the finder and then import to Photos. I would guess (and hope!) we'll see this added in an update, and hopefully soon!

  • How can I add an event to my calendar that occurs every third day...I have an ipad.

    How can I add an event to my calendar that occurs every third day?

    Do you happen to have a Mac?  If so, and if you use iCloud to sync your calendars, you can do that on your Mac and your iPad will understand.  But you cannot create such a repitition (or something like the third Tuesday of each month) on your iPad.
    In Calendar on your Mac, you would create the event, choose "Custom ..." as the repitition frequency, then choose "Days" and choose every 3 days.

  • How can I add the date to my locked screen on iPhone 5, i0S7

    How can I add the date to my locked screen on iPhone 5, i0S7

    The date is not showing up on the locked screen since I updated to the latest software.  Trust me, I looked for it before posting

  • HT201269 I have new iphone and all data were restored but my music! How can I add my music from Itunes and new iphone?

    I have new iphone and all data were restored but my music! How can I add my music from Itunes and new iphone?

    Connect the old phone to your computer, right click on it in iTunes, and choose Transfer Purchases. That should put all of your music in iTunes except any tracks that were not purchased from iTunes. If you have any such you will have to retrieve them from the original source, or see: https://discussions.apple.com/docs/DOC-3141.
    Apple also has this tip for copying data from an old phone to a new one.

Maybe you are looking for

  • Problems with FOI layer using mod_wl in Apache

    Hello everybody, I have published my application on web. I use MapViewer 1033 on Solaris 10 and Apache 2.0.59 on Windows XP. To proxy my requests I use mod_wl module in Apache. When I try to load base map everything is ok. But when I try to load FOI

  • How to create a 16x9 slideshow

    I'm looking for the best method to create a slideshow that ends up in 16x9, without stretching the images, for viewing on a large LCD HD TV. Something tells me that I might need to begin by cropping the original images in pre-processing, but I'd sure

  • QT Pro audio anomoly w ADVC-100

    iMac can capture a DVR Sound and Video from recorded DVD via ADVC-100. Sound and Video come in fine with FCE & iMovie. Can't seem to get sound to come in {or out} with QT Pro. Preferences are set to ADVC-100 and iMic USB {just as they are for the app

  • The parameters supplied for the batch are not valid.

    Error:The parameters supplied for the batch are not valid Stored Procedure is as follows CREATE PROCEDURE [dbo].[Usp_TrackVehicleDetails]  @reg_Number     NVARCHAR(25) AS BEGIN SET NOCOUNT ON;     DECLARE @Imei_Number    NVARCHAR(25), @Imei_Table NVA

  • TCODE VA01 - Delivery Plant determination for subitems

    A worklfow event is trigger and creates a sales order from a purchase order.  The system automatically assign a plant for the line item in the sale order from the main item, but our process demand that the system assign the correct delivery plant fro