Question: I'm working on getting the number of days between two dates using Java. When I give the application date as 27 it shows 0, and when I give as 26 it even shows 0. Is there anything wrong in my code? Any ideas would be greatly appreciated.

Here is my code 

```
  public static void main (String[] args) throws java.lang.Exception {            
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date currentDate = new Date();
        System.out.println("Current date:"+dateFormat.format(currentDate));
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strAppDate = "2014-10-28 15:11:30.0";
        Date appDate = formatter.parse(strAppDate);
        System.out.println("Application date :"+formatter.format(appDate));
        long diff = appDate.getTime() - currentDate.getTime();
        long diffDays = diff / (24 * 60 * 60 * 1000);
        System.out.println("Diff days :"+diffDays);
  }

```

Answer: 
You need to decide on the business rules. If there is less than a day difference, for example 23 hours, do you want to count that as 0 or round up to 1?

You `strAppDate` is `"2014-10-28 15:11:30.0"`, and depnding on your timezone, `currentDate` is the 27th, so the difference between `appDate.getTime()` and `currentDate.getTime()` is less than 24 hours, and `long diffDays = diff / (24 * 60 * 60 * 1000);` will be zero.

You can use doubles and always round up, or you can have some rules that determine the days difference depending on the hours difference. It really depends on how much precision you need.
If it's less than a day of difference, the result of the division operation will be zero, because that's how integer (and long integer) division works. You can try to divide by a `double` value:

```
double diffDays = diff / (24 * 60 * 60 * 1000.0);

```