Difference In Hours Between Two Dates And Times By Javascript
I have three input fields of type text in my html file. First input field is called OLD DATE & TIME. Second input field is called NEW DATE & TIME. Third Input field is cal
Solution 1:
If you want to use plain javascript then you can do calculations in this way..
var fromDate = parseInt(newDate(oldDate).getTime()/1000);
var toDate = parseInt(newDate(newDate).getTime()/1000);
var timeDiff = (toDate - fromDate)/3600; // will give difference in hrs
Solution 2:
Please use moment.js. this also can changing formate of date and time.
var now = "04/09/2013 15:00:00";
var then = "04/09/2013 14:20:30";
moment.utc(moment(now, "DD/MM/YYYY HH:mm:ss").diff(moment(then, "DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss")
Post a Comment for "Difference In Hours Between Two Dates And Times By Javascript"