Minute duration differentiation javascript - javascript

suppose I have this variable date in hour : minute : second format
var time1 = "12:34:19 PM"
var time2 = "12:29:25 PM"
How I get the differentiate (duration) from time1 and time2? And how we change it into date format to do diff process?

you can convert the time new Date() just prepend a date before it and
get their timestamp using getTime() and subtract them
var duration = new Date('datetime1').getTime() - new Date('datetime2').getTime()
since the timestamp is 1000 times than the result total seconds divide it by 1000
var duration = durantion/1000;
and I just create a function that format the seconds properly to makes it looks like a valid duration time
var time1 = "2016-11-02 12:34:19 PM"
var time2 = "2016-11-02 12:29:25 PM"
time1 = new Date(time1 ).getTime();
time2 = new Date(time2 ).getTime();
var duration = (time1 - time2) / 1000;
function formatTime(seconds) {
var minutes = Math.floor(((seconds/3600)%1)*60);
minutes = (minutes < 10) ? '0'+minutes : minutes;
var seconds = Math.round(((seconds/60)%1)*60);
seconds = (seconds < 10) ? '0'+seconds : seconds;
return minutes+':'+seconds;
}
console.log('Duration: ' + formatTime(duration)+' secs')

This is working script
String.prototype.toHHMMSS = function () {
var sec_num = parseInt(this, 10); // don't forget the second param
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
return hours+':'+minutes+':'+seconds;
}
var timeStart = new Date("Mon Jan 01 2007 11:00:00 GMT+0530").getTime();
var timeEnd = new Date("Mon Jan 01 2007 11:32:51 GMT+0530").getTime();
var hourDiff = timeEnd - timeStart; //in ms
var secDiff = (hourDiff / 1000).toString(); //in s
alert(secDiff .toHHMMSS());

You can create a Date objects using constructor like this:
Date(year, month, date, hours, minutes, seconds, ms)
in your case you can get diff:
var date = new Date(2000, 1, 1, 12, 34, 19, 0, 0),
date2 = new Date(2000, 1, 1, 12, 39, 25, 0, 0);
console.log(date2 - date); // in ms. You can do whatever you want with this value
you can read more about Date object here.

Related

How to get the number of days in a month

I make a countdown timer, I need to take the number of days in a month and subtract the days that have passed (for example: 30 days of September minus 8 days - the date is today).
Now I have to enter it manually:
const end = new Date(2021, 8, 30, 13, 0,12, 12);
You can get the number of days in a month using:
const getDays = (year, month) => new Date(year, month, 0).getDate()
const days = getDays(2021, 8)
console.log(days)
Days left in current month
var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var currentMonth = currentDate.getMonth();
var currentMonthLastDate = (new Date(currentYear, currentMonth, 0)).getDate();
var daysLeftInMonth = currentMonthLastDate - currentDate.getDate();
console.log(daysLeftInMonth);
A) If you won't only get the number of days in a month try this one:
<script>
function getDaysInMonth(month,year) {
var today = new Date().getDate();
// Here January is 1 based
// Day 0 is the last day in the previous month
// var monthDays = new Date(year, month, 0).getDate();
// Here January is 0 based
var monthDays = new Date(year, month+1, 0).getDate();
var remainDays = monthDays - today;
return remainDays;
}
console.log(getDaysInMonth(8, 2021));
</script>
B) If you want to get a full-timer to follow this one:
<div class="counter" style='color: green;'>
<span class='e-m-days'>0</span> Days |
<span class='e-m-hours'>8</span> Hours |
<span class='e-m-minutes'>0</span> Minutes |
<span class='e-m-seconds'>1</span> Seconds
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
function getCounterTimerData(obj) {
var days = parseInt($('.e-m-days', obj).text());
var hours = parseInt($('.e-m-hours', obj).text());
var minutes = parseInt($('.e-m-minutes', obj).text());
var seconds = parseInt($('.e-m-seconds', obj).text());
return seconds + (minutes * 60) + (hours * 3600) + (days * 3600 * 24);
}
function setCounterTimerData(s, obj) {
var days = Math.floor(s / (3600 * 24));
var hours = Math.floor((s % (60 * 60 * 24)) / (3600));
var minutes = Math.floor((s % (60 * 60)) / 60);
var seconds = Math.floor(s % 60);
console.log(days, hours, minutes, seconds);
$('.e-m-days', obj).html(days);
$('.e-m-hours', obj).html(hours);
$('.e-m-minutes', obj).html(minutes);
$('.e-m-seconds', obj).html(seconds);
}
var count = getCounterTimerData($(".counter"));
var timer = setInterval(function() {
count--;
if (count == 0) {
clearInterval(timer);
return;
}
setCounterTimerData(count, $(".counter"));
}, 1000);
});
</script>
Now you can set day, minutes, hours manually
var dt = new Date();
var month = dt.getMonth();
returns month
var year = dt.getFullYear();
var daysInMonth = new Date(year, month, 0).getDate();
// returns the diff

Countdown Hours Minutes Seconds

I'd like to create a countdown that count every hours, minutes, seconds remaining to 00:00:00 on July 13th at 12AM Miami time.
I'd like to addapt that code snippet and i struggle with calculs.
How shoud i adapt that code snippet for me to display hours, minutes, seconds instead of days, hours, minutes, seconds ?
How should i write the date for it to be 00:00:00 on July 13th at 12AM Miami time ?
What should i try next ?
Thanks.
<p id="demo"></p>
<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2022 15:37:25").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
-- WayneOS code snipped modification
// Format output-string
var outputHours = (hours < 10 ? '0' + hours : hours);
var outputMinutes = (minutes < 10 ? '0' + minutes : minutes);
var outputSeconds = (seconds < 10 ? '0' + seconds : seconds);
// Display the result in the element with id="demo"
if (distance > 0)
document.getElementById("hours").innerHTML = outputHours;
document.getElementById("minutes").innerHTML = outputMinutes;
document.getElementById("seconds").innerHTML = outputSeconds;
else
document.getElementById("hours").innerHTML = "EXPIRED";
}, 1000);
```
You could use a loop to calculate the hours, minutes and seconds until distance is smaller than 1000. For it to end on Jul 13 12:00:00 use new Date("Jul 13, 2021 12:00:00 GMT-4") Here is an example.
// Set the date we're counting down to
var countDownDate = new Date("Jul 13, 2021 12:00:00 GMT-4").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for hours, minutes and seconds
var hours = 0;
var minutes = 0;
var seconds = 0;
while (true)
if (distance >= (1000*60*60)) {
hours++;
distance -= (1000*60*60);
} else
if (distance >= (1000*60)) {
minutes++;
distance -= (1000*60);
} else
if (distance >= 1000) {
seconds++;
distance -= 1000;
} else
break;
// Format output-string
var hours = (hours < 10 ? '0' + hours : hours);
minutes = (minutes < 10 ? '0' + minutes : minutes);
seconds = (seconds < 10 ? '0' + seconds : seconds);
// Display the result in the element with id="demo"
if (distance > 0) {
document.getElementById("hours").innerHTML = hours;
document.getElementById("minutes").innerHTML = minutes;
document.getElementById("seconds").innerHTML = seconds;
} else
document.getElementById("hours").innerHTML = "EXPIRED";
}, 1000);
<div id="hours"></div>
<div id="minutes"></div>
<div id="seconds"></div>
If you have days, you can calculate the hours (days * 24 plus remaining hours). Here a little refactoring of your code. It uses setTimeout (more control and counting starts instantly) and a separate function to calculate the time units. See also.
Concerning the Miami time zone, you can create the date using timezone 'America/New_York'.
const getNextJuly13 = () => {
const now = new Date();
const miamiTime = new Date(`${
+(now.getMonth() > 6 && now.getDate() >= 13) + now.getFullYear()}/07/13 00:00`)
.toLocaleString('en', {timeZone: 'America/New_York'});
return new Date( miamiTime );
};
countDown(getNextJuly13(), document.querySelector("#demo"));
function countDown(until, writeTo) {
const distance = until - new Date();
const diffs = dateDiffCalc(distance);
const timeInfo4Demo = `\n\n=> Until ${
until.toLocaleString()} (your TZ: ${
Intl.DateTimeFormat().resolvedOptions().timeZone})\n${
JSON.stringify(diffs, null, 2)}`;
writeTo.textContent = `${diffs.totalHours}h ${
diffs.minutes}m ${diffs.seconds}s${timeInfo4Demo}`;
return distance >= 0
? setTimeout(() => countDown(until, writeTo), 1000)
: writeTo.textContent = "EXPIRED";
};
function dateDiffCalc(milliseconds) {
const secs = Math.floor(milliseconds / 1000);
const mins = Math.floor(secs / 60);
const hours = Math.floor(mins / 60);
const days = Math.floor(hours / 24);
return {
days,
hours: hours % 24,
totalHours: (days * 24) + (hours % 24),
minutes: mins % 60,
seconds: secs % 60,
};
}
<pre id="demo"></pre>

Could not calculate the time difference using JavaScript

I need to calculate time difference in hrs in between current date time and user input date time using JavaScript. Here is my code:
var user_date = '31-03-2019';
var dep_time='12:30PM';
var datePieces = user_date.split("-");
var mydate=[datePieces[1] , datePieces[0] , datePieces[2]].join("-");
var todayDate = new Date();
var todayMonth = todayDate.getMonth() + 1;
var todayDay = todayDate.getDate();
var todayYear = todayDate.getFullYear();
if (todayDay < 10) {
todayDay = '0' + todayDay;
}
if (todayMonth < 10) {
todayMonth = '0' + todayMonth;
}
var todayDateText = todayMonth + "-" + todayDay + "-" + todayYear;
var inputToDate = Date.parse(mydate);
var todayToDate = Date.parse(todayDateText);
//console.log(inputToDate, todayToDate);
//console.log(user_date, todayDateText);
if (inputToDate > todayToDate) {
var date=new Date;
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
var timeStart = new Date(todayToDate + strTime);
var timeEnd = new Date(mydate + dep_time);
console.log(timeStart);
console.log(timeEnd);
var diff = (timeEnd - timeStart) / 60000; //dividing by seconds and milliseconds
var minutes = diff % 60;
var hours = (diff - minutes) / 60;
alert(hours);
} else {
}
Here I getting the output NAN . I have both user input and current date time and I need the time difference in HRS.
1) The Date.parse method turns a date into milliseconds since January 1st, 1970. See https://www.w3schools.com/Jsref/jsref_parse.asp, therefore turning your user input date into milliseconds since January 1st, 1970.
2) In Javascript, the getTime() method on the new Date() object gets the number of milliseconds that have passed since January 1, 1970 until the current time.
3) Therefore, finding the difference of these milliseconds gives you the difference in milliseconds.
4) Since 1 hour = 3600000 ms, to find the difference in hours, divide your answer by 3600000, and get the difference in hours.
You also seem to forget to include the dep_time in parsing your date.
And the solution is below:
<script>
"use strict";
var user_date = '31-03-2019 12:30 PM';
var datePieces = user_date.split("-");
var mydate=[datePieces[1] , datePieces[0] , datePieces[2]].join("-");
var todayDate = new Date();
var todayToDate = todayDate.getTime();
// In JavaScript, getTime() gets the number of milliseconds that have passed since January 1, 1970.
var inputToDate = Date.parse(mydate);
if (inputToDate > todayToDate) {
var diff = (inputToDate - todayToDate) / 3600000; //Since 1 h = 3600000 ms
alert(diff);
} else {
var diff = (todayToDate - inputToDate) / 3600000; //Since 1 h = 3600000 ms
alert(diff);
}
</script>

Difference between two dates in minute, hours javascript

I want to find difference between two dates. I have tried this code but it gives me wrong values. I want get total minutes between two dates, so I am converting hours to minutes and adding to minutes.
var hourDiff = timeEnd - timeStart;
var diffHrs = Math.round((hourDiff % 86400000) / 3600000);
var diffMins = Math.round(((hourDiff % 86400000) % 3600000) / 60000);
diffMins = diffMins + (diffHrs * 60);
Here timeEnd is Mon Jan 01 2007 11:30:00 GMT+0530 (India Standard Time),
and timeStart is Mon Jan 01 2007 11:00:00 GMT+0530 (India Standard Time).
Here if hours difference I am getting 1, it should be 0 and minutes I am getting 30 that is right. But hours should be 0. Am I doing something wrong here?
Try this code (uses ms as initial units)
var timeStart = new Date("Mon Jan 01 2007 11:00:00 GMT+0530").getTime();
var timeEnd = new Date("Mon Jan 01 2007 11:30:00 GMT+0530").getTime();
var hourDiff = timeEnd - timeStart; //in ms
var secDiff = hourDiff / 1000; //in s
var minDiff = hourDiff / 60 / 1000; //in minutes
var hDiff = hourDiff / 3600 / 1000; //in hours
var humanReadable = {};
humanReadable.hours = Math.floor(hDiff);
humanReadable.minutes = minDiff - 60 * humanReadable.hours;
console.log(humanReadable); //{hours: 0, minutes: 30}
JSFiddle: http://jsfiddle.net/n2WgW/
Try:
var diffHrs = Math.floor((hourDiff % 86400000) / 3600000);
Math.round rounded the 0.5 hour difference up to 1. You only want to get the "full" hours in your hours variable, do you remove all the minutes from the variable with the Math.floor()
Try this:
var startDate = new Date('Jan 01 2007 11:00:00');
var endDate = new Date('Jan 01 2007 11:30:00');
var starthour = parseInt(startDate.getHours());
var endhour = parseInt(endDate.getHours());
if(starthour>endhour){
alert('Hours diff:' + parseInt(starthour-endhour));
}
else{
alert('Hours diff:' + parseInt(endhour-starthour));
}
And here is the working fiddle.
If you are confident that the difference will be less that 24 hours, the following works.
var timeStart= new Date('2015-01-01 03:45:45.890');
var timeEnd = new Date('2015-01-01 05:12:34.567');
var timeDiff = new Date(timeEnd.getTime() - timeStart.getTime());
var humanTime = timeDiff.toISOString().substring(11, 23);
var diffHours = timeDiff.toISOString().substring(11, 12);
humanTime is 01:26:48.677, diffHours is 01
You can Try This:-
function diff_hours(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60 * 60); // For Hours
//diff /= (60); For Minutes
return Math.abs(Math.round(diff));
}
dt1 = new Date(2014,10,2);
dt2 = new Date(2014,10,3);
console.log(diff_hours(dt1, dt2)); // you will get '24' hours
dt1 = new Date("October 13, 2014 08:11:00");
dt2 = new Date("October 13, 2014 11:13:00");
console.log(diff_hours(dt1, dt2)); // you will get '3' hours
var timeDiff = function (date1, date2) {
var a = new Date(date1).getTime(),
b = new Date(date2).getTime(),
diff = {};
diff.milliseconds = a > b ? a % b : b % a;
diff.seconds = diff.milliseconds / 1000;
diff.minutes = diff.seconds / 60;
diff.hours = diff.minutes / 60;
diff.days = diff.hours / 24;
diff.weeks = diff.days / 7;
return diff;
}
You can get Time difference in hours minutes and secons like countdown by using following:
var diff = EndedTime - StartedTime;
var hours = Math.floor(diff / 3.6e6);
var minutes = Math.floor((diff % 3.6e6) / 6e4);
var seconds = Math.floor((diff % 6e4) / 1000);
var duration = hours+":"+minutes+":"+seconds;
Hope This Help. Thanks
You can get Time Difference in hours and minutes format like below
const startTime = new Date(event.startTime);
const endTime = new Date(event.endTime);
const diff = endTime.getTime() - startTime.getTime();
const hrDiff = diff / 3600 / 1000; // 1.555555
const totalHours = parseFloat((hrDiff).toFixed(2)); // 1.5

JavaScript - Get minutes between two dates

If I have two dates, how can I use JavaScript to get the difference between the two dates in minutes?
You may checkout this code:
var today = new Date();
var Christmas = new Date(today.getFullYear() + "-12-25");
var diffMs = (Christmas - today); // milliseconds between now & Christmas
var diffDays = Math.floor(diffMs / 86400000); // days
var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
console.log(diffDays + " days, " + diffHrs + " hours, " + diffMins + " minutes until Christmas =)");
or var diffMins = Math.floor((... to discard seconds if you don't want to round minutes.
Subtracting two Date objects gives you the difference in milliseconds, e.g.:
var diff = Math.abs(new Date('2011/10/09 12:00') - new Date('2011/10/09 00:00'));
Math.abs is used to be able to use the absolute difference (so new Date('2011/10/09 00:00') - new Date('2011/10/09 12:00') gives the same result).
Dividing the result by 1000 gives you the number of seconds. Dividing that by 60 gives you the number of minutes. To round to whole minutes, use Math.floor or Math.ceil:
var minutes = Math.floor((diff/1000)/60);
In this example the result will be 720.
[edit 2022] Added a more complete demo snippet, using the aforementioned knowledge.
See also
untilXMas();
function difference2Parts(milliseconds) {
const secs = Math.floor(Math.abs(milliseconds) / 1000);
const mins = Math.floor(secs / 60);
const hours = Math.floor(mins / 60);
const days = Math.floor(hours / 24);
const millisecs = Math.floor(Math.abs(milliseconds)) % 1000;
const multiple = (term, n) => n !== 1 ? `${n} ${term}s` : `1 ${term}`;
return {
days: days,
hours: hours % 24,
hoursTotal: hours,
minutesTotal: mins,
minutes: mins % 60,
seconds: secs % 60,
secondsTotal: secs,
milliSeconds: millisecs,
get diffStr() {
return `${multiple(`day`, this.days)}, ${
multiple(`hour`, this.hours)}, ${
multiple(`minute`, this.minutes)} and ${
multiple(`second`, this.seconds)}`;
},
get diffStrMs() {
return `${this.diffStr.replace(` and`, `, `)} and ${
multiple(`millisecond`, this.milliSeconds)}`;
},
};
}
function untilXMas() {
const nextChristmas = new Date(Date.UTC(new Date().getFullYear(), 11, 25));
const report = document.querySelector(`#nextXMas`);
const diff = () => {
const diffs = difference2Parts(nextChristmas - new Date());
report.innerHTML = `Awaiting next XMas 🙂 (${
diffs.diffStrMs.replace(/(\d+)/g, a => `<b>${a}</b>`)})<br>
<br>In other words, until next XMas lasts…<br>
In minutes: <b>${diffs.minutesTotal}</b><br>In hours: <b>${
diffs.hoursTotal}</b><br>In seconds: <b>${diffs.secondsTotal}</b>`;
setTimeout(diff, 200);
};
return diff();
}
body {
font: 14px/17px normal verdana, arial;
margin: 1rem;
}
<div id="nextXMas"></div>
var startTime = new Date('2012/10/09 12:00');
var endTime = new Date('2013/10/09 12:00');
var difference = endTime.getTime() - startTime.getTime(); // This will give difference in milliseconds
var resultInMinutes = Math.round(difference / 60000);
A simple function to perform this calculation:
function getMinutesBetweenDates(startDate, endDate) {
var diff = endDate.getTime() - startDate.getTime();
return (diff / 60000);
}
That's should show the difference between the two dates in minutes. Try it in your browser:
const currDate = new Date('Tue Feb 13 2018 13:04:58 GMT+0200 (EET)')
const oldDate = new Date('Tue Feb 13 2018 12:00:58 GMT+0200 (EET)')
(currDate - oldDate) / 60000 // 64
This problem is solved easily with moment.js, like this example:
var difference = mostDate.diff(minorDate, "minutes");
The second parameter can be changed for another parameters, see the moment.js documentation.
e.g.: "days", "hours", "minutes", etc.
http://momentjs.com/docs/
The CDN for moment.js is available here:
https://cdnjs.com/libraries/moment.js
Thanks.
EDIT:
mostDate and minorDate should be a moment type.
EDIT 2:
For those who are reading my answer in 2020+, momentjs is now a legacy project.
If you are still looking for a well-known library to do this job, I would recommend date-fns.
// How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
var result = differenceInMinutes(
new Date(2014, 6, 2, 12, 20, 0),
new Date(2014, 6, 2, 12, 7, 59)
)
//=> 12
You can do as follows:
Get difference of dates(Difference will be in milliseconds)
Convert milliseconds into minutes i-e ms/1000/60
The Code:
let dateOne = new Date("2020-07-10");
let dateTwo = new Date("2020-07-11");
let msDifference = dateTwo - dateOne;
let minutes = Math.floor(msDifference/1000/60);
console.log("Minutes between two dates =",minutes);
For those that like to work with small numbers
const today = new Date();
const endDate = new Date(startDate.setDate(startDate.getDate() + 7));
const days = parseInt((endDate - today) / (1000 * 60 * 60 * 24));
const hours = parseInt(Math.abs(endDate - today) / (1000 * 60 * 60) % 24);
const minutes = parseInt(Math.abs(endDate.getTime() - today.getTime()) / (1000 * 60) % 60);
const seconds = parseInt(Math.abs(endDate.getTime() - today.getTime()) / (1000) % 60);
Here's some fun I had solving something similar in node.
function formatTimeDiff(date1, date2) {
return Array(3)
.fill([3600, date1.getTime() - date2.getTime()])
.map((v, i, a) => {
a[i+1] = [a[i][0]/60, ((v[1] / (v[0] * 1000)) % 1) * (v[0] * 1000)];
return `0${Math.floor(v[1] / (v[0] * 1000))}`.slice(-2);
}).join(':');
}
const millis = 1000;
const utcEnd = new Date(1541424202 * millis);
const utcStart = new Date(1541389579 * millis);
const utcDiff = formatTimeDiff(utcEnd, utcStart);
console.log(`Dates:
Start : ${utcStart}
Stop : ${utcEnd}
Elapsed : ${utcDiff}
`);
/*
Outputs:
Dates:
Start : Mon Nov 05 2018 03:46:19 GMT+0000 (UTC)
Stop : Mon Nov 05 2018 13:23:22 GMT+0000 (UTC)
Elapsed : 09:37:02
*/
You can see it in action at https://repl.it/#GioCirque/TimeSpan-Formatting
The following code worked for me,
function timeDiffCalc(dateNow,dateFuture) {
var newYear1 = new Date(dateNow);
var newYear2 = new Date(dateFuture);
var dif = (newYear2 - newYear1);
var dif = Math.round((dif/1000)/60);
console.log(dif);
}
It works easily:
var endTime = $("#ExamEndTime").val();
var startTime = $("#ExamStartTime").val();
//create date format
var timeStart = new Date("01/01/2007 " + startTime);
var timeEnd = new Date("01/01/2007 " + endTime);
var msInMinute = 60 * 1000;
var difference = Math.round(Math.abs(timeEnd - timeStart) / msInMinute);
$("#txtCalculate").val(difference);
this will work
duration = moment.duration(moment(end_time).diff(moment(start_time)))

Categories