Get days difference between two dates - Node.js Date

Node.js examples for Date:Date Calculation

Description

Get days difference between two dates

Demo Code

  /**//from w ww. j  av a2 s.  c o m
   * Get days difference between two dates
   * @param date1
   * @param date2
   * @returns {number}
   */
  daysDiff: function( date1, date2) {
    var lastFuelDate = new Date(date1);
    var lastLastFuelDate = new Date(date2);
    var timeDiff = Math.abs(lastLastFuelDate.getTime() - lastFuelDate.getTime());
    return Math.ceil(timeDiff / (1000 * 3600 * 24));
  },

Related Tutorials