How to compare only date in moment.js

I am new to moment.js. I have a date object and it has some time associated with it. I just want to check if that date is greater than or equal to today's date, excluding the time when comparing.

 var dateToCompare = 2015-04-06T18:30:00.000Z

I just want to check if dateToCompare is equal or greater than today's date. I have checked isSame of moment.js, but it seems to take string and only the date part. But I do not want to convert my date to string or manipulate it further. Because I am worried that javascript may do something unexpected when converting that date to string(like adding the offset or dst,etc), or may be I am wrong.

Sample isSame() from docs

moment('2010-10-20').isSame('2010-10-20');

Also I am looking for something like isSame() and isAfter() combined as one statement.

I need to compare using moment.js only.Please do not suggest plain javascript date comparison.


The docs are pretty clear that you pass in a second parameter to specify granularity.

If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.

moment('2010-10-20').isAfter('2010-01-01', 'year'); // false
moment('2010-10-20').isAfter('2009-12-31', 'year'); // true

As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.

For your case you would pass 'day' as the second parameter.

MomentJS Day diff dates only excluding time, var ExpiryDate = new Date("11/13/2014 11:13:00"); var daysDiff = moment(ExpiryDate). diff(moment(Date. now()), 'days'); Using Moment.js. If you have the option of including a third-party library, it's definitely worth taking a look at Moment.js. It makes working with Date and DateTime much, much easier. For example, seeing if one Date comes after another Date but excluding their times, you would do something like this:


Meanwhile you can use the isSameOrAfter method:

moment('2010-10-20').isSameOrAfter('2010-10-20', 'day');

Compare only timepart in moment object, I have included a Snippet that at the moment does not work as intended. The filter function is not working properly. I want to filter out all dates  Moment.js offers a way to calculate the difference between two dates. The difference is calculated in milliseconds by default, but can also be returned in days, months, years, etc. To compute the


In my case i did following code for compare 2 dates may it will help you ...

var date1 = "2010-10-20";
var date2 = "2010-10-20";
var time1 = moment(date1).format('YYYY-MM-DD');
var time2 = moment(date2).format('YYYY-MM-DD');
if(time2 > time1){
	console.log('date2 is Greter than date1');
}else if(time2 > time1){
	console.log('date2 is Less than date1');
}else{
	console.log('Both date are same');
}
<script src="https://momentjs.com/downloads/moment.js"></script>

Is Same, isSame(Moment|String|Number|Date|Array, String); Check if a moment is the same as another moment. The first argument will be parsed as a moment, if not already so. If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter. Note: This method alters the original date. For 'day' it literally sets minutes, seconds and hours for the existing object to 0 (so it is very fast). In this case you're creating a new object and altering it so there are no actual side effects but if you were to do ExpiryDate.startOf('day') without creating a new moment then it would change the original.


You could use startOf('day') method to compare just the date

Example :

var dateToCompare = moment("06/04/2015 18:30:00");
var today = moment(new Date());

dateToCompare.startOf('day').isSame(today.startOf('day'));

No way to (easily) compare the date part of 2 moments · Issue #1269 , I have been digging through docs and racking my brain, but it seems that taking two moment objects and comparing just the date (whole date)  Comparing two times with Moment JS. Ask Question Asked 6 years, Moment js date time comparison. 386. Get hours difference between two dates in Moment Js. 1.


How to compare only HH:mm? · Issue #1199 · moment/moment , I need (want) the day/date to be ignored. Use case: I'm reading a schedule w/ start & end times from a config file. This is done using Node.js. I'm able to get the difference between two dates using MomentJs as follows: moment(end.diff(startTime)).format("m[m] s[s]") However, I also want to display the hour when applicable (only when >= 60 Stack Overflow


Docs, only needing core define(['moment'], function (moment) To get the current date and time, just call moment() with no parameters. var now = moment();. This is  If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L, LL, etc.) – AJ Richardson Apr 2 '18 at 21:46 Why you set MMM three times.


Guides, There is a logical difference between time math and date math. In Moment.js time math assumes a linear time scale, just  moment ().subtract ('seconds', 1); // Deprecated in 2.8.0 moment ().subtract (1, 'seconds'); As of 2.12.0 when decimal values are passed for days and months, they are rounded to the nearest integer. Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer.