Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript get hours difference between two dates

// date1 and date2 are date objects

let hours = Math.abs(date1 - date2) / 36e5;

// The subtraction returns the difference between the two dates in milliseconds.
// 36e5 is the scientific notation for 60*60*1000, dividing by which converts
// the milliseconds difference into hours.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #hours #difference #dates
ADD COMMENT
Topic
Name
8+2 =