I would like to check if two date exceeds a week, like, check if two dates have seven days,
at point the data range should be within a week only(7 Days).
i have tried something like this,
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class IsDateRangeExceedsWeek
{
public static void main( String[] args )
{
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date fromDate = sdf.parse("2015-05-01");
Date toDate = sdf.parse("2015-05-07");
System.out.println(sdf.format(fromDate));
System.out.println(sdf.format(toDate));
if(fromDate.compareTo(toDate)>0){
System.out.println("From Date should be less than To Date");
} else if(fromDate.compareTo(toDate)==0){
System.out.println("From Date is equal to To Date");
}
}catch(ParseException ex){
ex.printStackTrace();
}
}
}
Could some one help ?