get time difference in minutes in javascript

we created java-script function named “getTheDiffTime” using that function you will be able to fetch the time difference in various format.

javascript get time difference in minutes

01function getTheDiffTime(dateone, datetwo,format){
02//format = "Days", Hours, Minutes, Seconds
03if(dateone > datetwo) {
04var seconds = dateone.getTime() - datetwo.getTime();
05} else {
06var seconds = datetwo.getTime() - dateone.getTime();
07}
08var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;
09if(format=="Days"){
10var rformat = Math.floor(seconds / day);
11seconds -= rformat * day;
12//alert("days: "+rformat);
13}else if(format=="Hours"){
14// find the hours
15rformat = translate(seconds / hour);
16//alert("hours: "+rformat);
17}else if (format=="Minutes"){
18//find the mintues
19rformat= translate(seconds / minute);
20//alert("minutes: "+ rformat);
21}else if(format=="Seconds"){
22//find the seconds
23rformat = translate(seconds / second);
24//alert("seconds: "+rformat);
25}
26 
27return rformat
28//alert(rformat);
29 
30}

How to use this function here I am giving you the one good example.

I am going to get the current months minutes using this function.

1//for calculating the current month in mintue -script
2currentMonth = new Date();
3plus_oneMonth = new Date();
4plus_oneMonth.setMonth(plus_oneMonth.getMonth()+1);
5 
6getTheDiffTime(plus_oneMonth,currentMonth,"Minutes");

You will get return the minutes.