title: Comparing dates in milliseconds
body: <p>Say I have two date fields receiveDate and currentDate. I want to check if receiveDate was 5 days before currentDate. What I did was to convert the dates in milliseconds and then compare against 5. Is there a better way of doing so? If so, how and why mine is any less better? Thanks.</p>
  
  <p>Method I wrote -</p>
  
  <pre><code>private static final double DAY_IN_MILLISECONDS = 86400000;
  
  // Param date is the receivedDate
  private long getDaysOld(final Date date) {
  
  
      Calendar suppliedDate = Calendar.getInstance();
      suppliedDate.setTime(date);
      Calendar today = Calendar.getInstance();
      today.setTime(currentDate);
  
      double ageInMillis = (today.getTimeInMillis() - suppliedDate.getTimeInMillis());
      double tempDouble;
  
      if(isEqual(ageInMillis, 0.00) || isGreaterThan(Math.abs(ageInMillis), DAY_IN_MILLISECONDS)) {
          tempDouble =  ageInMillis / DAY_IN_MILLISECONDS;
      } else {
          tempDouble =  DAY_IN_MILLISECONDS / ageInMillis;
      }
  
      long ageInDays = Math.round(tempDouble);
  
      return ageInDays;
  
  
  }
  </code></pre>
  
  <p>Then I have something like-</p>
  
  <pre><code>long daysOld = getDaysOld(receivedDate) ;   
  if(daysOld &lt;= 5) {
      .... some business code ....
  }
  </code></pre>