Try getting the times in milliseconds and comparing them:
Date startDate = Start.getDate();
Date endDate = End.getDate();
// In milliseconds
long difference = endDate.getTime() - startDate.getTime();
int diffInDays = (int)(difference / 1000 / 60 / 60 / 24);
Before you were subtracting the Date
objects, which aren't numbers. You want to compare their times, which are numbers.
To check if the JDateChooser
is null, just do:
if (Start == null) {
// code
}
or
if (Start != null) {
// code
}
Disclaimer:
You should NEVER subtract two milliseconds from each other,there are just to many rules which aren't taking into account (leap years, leap seconds, century boundaries, daylight savings) to make it even remotely accurate. You should either use Java 8's Time API or JodaTi e (oh and days aren't always 24 hours long). -MadProgrammer.
This is a quick and dirty solution, but there are a lot of weak edge cases. Take caution.