abs(date1_ms - date2_ms)
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY)
//-->
</script>
This function accepts two Date object argumentsdate1 and date2. Note that
is doesn't matter which date is earlier or later because this function calculate
s the absolute value of the difference between them. The constant ONE_DAY stores
the number of milliseconds in a day, and then the two dates are converted into
milliseconds using the getTime() method. The results are stored in the variables
date1_ms and date2_ms.
Next the following statement calculates the absolute value, in milliseconds, of
the difference between the two dates:
var difference_ms = Math.abs(date1_ms - date2_
|