Reputation: 2379
I am using momentjs for date and I have one date string, ie,"2015-05-10"
,I want to get date difference from today
var today= moment().format('YYYY-MM-DD');
How it is possible here?
Upvotes: 2
Views: 3105
Reputation: 21901
here is a example,
var now = moment(); // moment object of now
var day = moment("2015-05-13"); // moment object of other date
$scope.difference = now.diff(day, 'days'); // calculate the difference in days
$scope.difference = now.diff(day, 'hours'); // calculate the difference in hours
check more options here
here is a example
Upvotes: 3
Reputation: 7117
if you are talking about time difference in hours
var now = "04/09/2013 15:00:00";
var then = "02/09/2013 14:20:30";
var ms = moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss"));
var d = moment.duration(ms);
var s = Math.floor(d.asHours()) + moment.utc(ms).format(":mm:ss");
Upvotes: 0