1const date1 = new Date('7/13/2010');
2const date2 = new Date('12/15/2010');
3console.log(getDifferenceInDays(date1, date2));
4console.log(getDifferenceInHours(date1, date2));
5console.log(getDifferenceInMinutes(date1, date2));
6console.log(getDifferenceInSeconds(date1, date2));
7
8function getDifferenceInDays(date1, date2) {
9 const diffInMs = Math.abs(date2 - date1);
10 return diffInMs / (1000 * 60 * 60 * 24);
11}
12
13function getDifferenceInHours(date1, date2) {
14 const diffInMs = Math.abs(date2 - date1);
15 return diffInMs / (1000 * 60 * 60);
16}
17
18function getDifferenceInMinutes(date1, date2) {
19 const diffInMs = Math.abs(date2 - date1);
20 return diffInMs / (1000 * 60);
21}
22
23function getDifferenceInSeconds(date1, date2) {
24 const diffInMs = Math.abs(date2 - date1);
25 return diffInMs / 1000;
26}
1const date1 = new Date('7/13/2010');
2const date2 = new Date('12/15/2010');
3const diffTime = Math.abs(date2 - date1);
4const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
5console.log(diffTime + " milliseconds");
6console.log(diffDays + " days");
1var date1 = new Date();
2 var date2 = new Date("2025/07/30 21:59:00");
3
4showDiff(date1,date2);
5
6function showDiff(date1, date2){
7
8 var diff = (date2 - date1)/1000;
9 diff = Math.abs(Math.floor(diff));
10
11 var days = Math.floor(diff/(24*60*60));
12 var leftSec = diff - days * 24*60*60;
13
14 var hrs = Math.floor(leftSec/(60*60));
15 var leftSec = leftSec - hrs * 60*60;
16
17 var min = Math.floor(leftSec/(60));
18 var leftSec = leftSec - min * 60;
19 console.info("You have " + days + " days " + hrs + " hours " + min + " minutes and " + leftSec + " seconds");
20
21 return {
22 d: days,
23 h: hrs,
24 i: min,
25 s: leftSec
26 };
27}
1Gettings diffrence between daytes