Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited body
Source Link
Joshua Pinter
  • 47.9k
  • 23
  • 261
  • 258

Using Moment.js

If you have the option of including a third party-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:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.

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:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.

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:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.

added 2 characters in body
Source Link
Joshua Pinter
  • 47.9k
  • 23
  • 261
  • 258

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 DatesDate and DateTimesDateTime much, much easier.

For example, seeing if one Date comes after another Date but excluding their times, you would do something like this:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.

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 Dates and DateTimes much, much easier.

For example, seeing if one Date comes after another Date but excluding their times, you would do something like this:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.

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:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.

Source Link
Joshua Pinter
  • 47.9k
  • 23
  • 261
  • 258

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 Dates and DateTimes much, much easier.

For example, seeing if one Date comes after another Date but excluding their times, you would do something like this:

var date1 = new Date(2016,9,20,12,0,0); // October 20, 2016 12:00:00 var date2 = new Date(2016,9,20,12,1,0); // October 20, 2016 12:01:00 // Comparison including time. moment(date2).isAfter(date1); // => true // Comparison excluding time. moment(date2).isAfter(date1, 'day'); // => false 

The second parameter you pass into isAfter is the precision to do the comparison and can be any of year, month, week, day, hour, minute or second.