Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

compare date value in javascript

Comparing two dates is as simple as

var differenceInMs = dateNewer - dateOlder;
So, convert the timestamps back into Date instances

var d1 = new Date('2013-08-02T10:09:08Z'), // 10:09 to
    d2 = new Date('2013-08-02T10:20:08Z'); // 10:20 is 11 mins
Get the difference

var diff = d2 - d1;
Format this as desired

if (diff > 60e3) console.log(
    Math.floor(diff / 60e3), 'minutes ago'
);
else console.log(
    Math.floor(diff / 1e3), 'seconds ago'
);
// 11 minutes ago
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #compare #date #javascript
ADD COMMENT
Topic
Name
1+6 =