forked from parse-community/parse-server-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateUtil.js
More file actions
20 lines (20 loc) · 829 Bytes
/
DateUtil.js
File metadata and controls
20 lines (20 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
exports.getMinutesBetweenDates = function(startDate, endDate) {
var diff = endDate.getTime() - startDate.getTime();
return (diff / 60000);
}
exports.getDaysBetweenDates = function(startDate, endDate) {
var diff = endDate.getTime() - startDate.getTime();
return Math.round(Math.abs(diff / 86400000)); // 86400000 == 24*60*60*1000 == hours*minutes*seconds*milliseconds
}
//from http://stackoverflow.com/questions/2536379/difference-in-months-between-two-dates-in-javascript/15158873#15158873
exports.getMonthsBetweenDates = function(startDate, endDate) {
var year1=startDate.getFullYear();
var year2=endDate.getFullYear();
var month1=startDate.getMonth();
var month2=endDate.getMonth();
if(month1===0){ //Have to take into account
month1++;
month2++;
}
return Math.abs((year2 - year1) * 12 + (month2 - month1));
}