Link to home
Start Free TrialLog in
Avatar of Millkind
MillkindFlag for Afghanistan

asked on

Find if date is between two dates

I have three dates stored as strings as mmddyyyy
one is start
two is end
three is entered by user

I want to see if three is between one and two.

I've looked through the calendar class at sun and am confused about it.
This needs to be done in JSP
 
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

well there are two ways of doing it...
one which is easy wd go something like this..

convert all the dates in YYYYMMDD
convert them in number and see if third number falls within the range.. ( simple mathmatics)..
since you have got them in string format all you will have to do with each of them is..

String date1 = request.getParameter("date1");

if(date1!=null &&date1.length()=8)
{
String years=date1.subString(4);
String rest = date1.subString(0,4);
date1=years+rest;
}
int ncdate1=new Integer(date1).intValue();

Do the same stuff with all three and after that is a small if condition as

if(ndat1<ndate2<ndate3)
{
yes
}

// PS I am very pethatic with substring numbers so please check them before using the above code as is..
Avatar of Mick Barry
Use SimpleDateFormat to first parse them into Dates and then use the before() and after() methods to check if date is between the two.
yup thats the second method which I forgot to mention ( thanks Objects)
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Millkind

ASKER

I've got it. Thanks to all who helped and many of the answers did so im gonna split the points up.