CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Posts
    21

    date Manipulation

    I want to compare two dates.
    Ok the scenerio is this. I have

    String responsemonth;
    String responseyear;
    String responseday;

    I want to get the current date and compare the two. The above date has to be less than the current date. If it is not I display a message.
    I tried using Calender class but I could not subtract from the current date. Can somebody help me.

    I need to do similar thing for two dates. where both will be in the form of varible and then I have to create the Date object to do the comapre.
    Any Suggestion for both will be greately appreciated.

    Thanks.
    Garry





  2. #2
    Join Date
    May 2000
    Location
    NJ,USA
    Posts
    64

    Re: date Manipulation

    HI,
    Look at this code..
    Calendar cal = Calendar.getInstance();
    Date dt1 = cal.getTime();
    int year = dt1.getYear() + 1900;
    int month = dt1.getMonth() + 1;
    String stDt = month + "/" + dt1.getDate() + "/" + year;
    Date stDate = new Date(stDt); //current date
    String endDt = "10/10/2000"; //argument date
    Date endDate = new Date(endDt);
    int num = stDate.compareTo(endDate);

    If num = 0 then both dates are same
    num > 0 then endDate > stDate
    num < 0 then endDate < stDate

    Hope it will help U,
    Sreeni
    #If this post is valid to u, then dont forget to rate it#


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured