Reputation: 4732
$.each(data[i].replies, function(m, n) {
var currentdate = new Date();
console.log(n.entry.date_entered);
check = moment(n.entry.date_entered, 'YYYY/MM/DD');
check1 = moment(currentdate, 'YYYY/MM/DD');
console.log(check);
console.log(check1);
var month = check.format('M');
var day = check.format('DD');
var year = check.format('YYYY');
var month1 = check1.format('M');
var day1 = check1.format('DD');
var year1 = check1.format('YYYY');
get = moment([year, month, day]);
get1 = moment([year1, month1, day1]);
g = get1.from(get);
});
Sample n.entry.date_entered
: 2014-07-28 12:23:43
For all the dates i am getting a few seconds ago don't know why
Upvotes: 1
Views: 72
Reputation: 16570
I think your problem is the format mask that you pass in to moment
.
In your sample you use -
as the delimiter but in your format mask you use /
. This way moment
will not be able to parse the date and will give you the current date instead.
Try changing your format mask to "YYYY-MM-DD"
.
Upvotes: 1