.day() returns wrong day of month with Moment.js
This how to get parts of date:
var date = moment("12-25-1995", "MM-DD-YYYY");
if (date.isValid()) {
day = date.date();
console.log('day ' + day);
month = date.month() + 1;
console.log('month ' + month);
year = date.year();
console.log('year '+ urlDateMoment.year());
} else {
console.log('Date is not valid! ');
}
The correct function to use is .date()
:
date.date() === 25;
.day()
gives you the day of the week. This works similarly to javascript's .getDate()
and .getDay()
functions on the date object.
If you want to get the month and year, you can use the .month()
and .year()
functions.