Click to See Complete Forum and Search --> : date Manipulation


Garry
October 9th, 2000, 09:05 PM
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

vasgaddam
October 10th, 2000, 10:34 AM
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#