javascript - Diff between two dates (datetime) in minutes -


this question has answer here:

i need check difference between 2 dates - db , actual, in minutes in js/jquery (i need run function check ajax).
format of date:

19-01-2016 22:18 

i need this:

if ( (date_actual - date_db) < 1 minute ) {    //do } 

how can this?

edit: created this, getting same log, it's not change - http://jsbin.com/xinaki/edit?js,console

edit 2: here it's working code, but it's checking in same hour/minute, ex. 12:50:50 , 12:50:58 show log 2 seconds, need 'stay' log on 1 minute
http://jsbin.com/laruro/edit?js,console

assuming dates in same format, , strings, use helper function convert 1 or both of strings real date() object:

var makedate = function(datestring) {   var d = datestring.split(/[\s:-]+/);   return new date(d[2],d[1] - 1,d[0],d[3],d[4]); } 

and use compare a string current date:

var diffinmin = function(datestring) {   return ( new date() /* < current date */ - makedate(datestring) ) / ( 1000 * 60 ); }; 

or compare two date strings:

var diffinmin = function(datestring1, datestring2) {   // assumes date string 1 more recent datestring2   return ( makedate(datestring1) - makedate(datestring2) ) / ( 1000 * 60 );  }; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -