Moment.js has been successfully used in millions of projects, and we are happy to have contributed to making date and time better on the web. As of September 2020, Moment gets over 12 million downloads per week Donate. Some Moment.js users may have a little extra money. Please support these charities: Black Lives Matter Foundation Equal Justice Initiativ MomentJS - Is Same - This method will check if the moment is same as another moment. It returns true or false If you try moment(28-02-1999), you get an invalid date. So comparing x to an invalid date string returns false. So comparing x to an invalid date string returns false. To fix it, either use the default date format (ISO 8601)
Yeah, I understand the confusion. Without knowing that we mean 3:30am is the next day it is tricky. Disregarding the day/date: If I ask, is 11pm between 9pm and 3am I expect the answer to be true. If I ask, is 11pm between 3am and 9pm I expect the answer to be false.. Since I can't simply ignore the date using moment I started checking for ALL times before/after 12 and ended up with Like moment#isSame, moment#isBefore, moment#isAfter any of the units of time that are supported for moment#startOf are supported for moment#isBetween. Year, month, week, isoWeek, day, hour, minute, and second. Version 2.13.0 introduces inclusivity. A [indicates inclusion of a value. A (indicates exclusion. If the inclusivity parameter is used. Moment.js - Get difference between two dates in years, months and days. Updated on September 15, 2019 Kisan Patel You could get the difference in years and add that to the initial date; then get the difference in months and add that to the initial date again. In doing so, you can now easily get the difference in days and avoid using the modulo operator as well. var a = moment([2015, 11, 29. Like moment#isSame and moment#isBefore, any of the units of time that are supported for moment#startOf are supported for moment#isAfter. year month week isoWeek day hour minute second If nothing is passed to moment#isAfter, it will default to the current time. moment().isAfter(); // fals Moment.js also provides various date comparison methods. These methods include isBefore() , isAfter() , and isSame() which, as the names imply, return a Boolean indicating if one date is before.