I believe you are looking for the query functions, isBefore, isSame, and isAfter.

But it's a bit difficult to tell exactly what you're attempting. Perhaps you are just looking to get the difference between the input time and the current time? If so, consider the difference function, diff. For example:

moment().diff(date_time, 'minutes')

A few other things:

  • There's an error in the first line:

      var date_time = 2013-03-24 + 'T' + 10:15:20:12 + 'Z'
    

    That's not going to work. I think you meant:

      var date_time = '2013-03-24' + 'T' + '10:15:20:12' + 'Z';
    

    Of course, you might as well:

      var date_time = '2013-03-24T10:15:20:12Z';
    
  • You're using: .tz('UTC') incorrectly. .tz belongs to moment-timezone. You don't need to use that unless you're working with other time zones, like America/Los_Angeles.

    If you want to parse a value as UTC, then use:

      moment.utc(theStringToParse)
    

    Or, if you want to parse a local value and convert it to UTC, then use:

      moment(theStringToParse).utc()
    

    Or perhaps you don't need it at all. Just because the input value is in UTC, doesn't mean you have to work in UTC throughout your function.

  • You seem to be getting the "now" instance by moment(new Date()). You can instead just use moment().

Updated

Based on your edit, I think you can just do this:

var date_time = req.body.date + 'T' + req.body.time + 'Z';
var isafter = moment(date_time).isAfter('2014-03-24T01:14:00Z');

Or, if you would like to ensure that your fields are validated to be in the correct format:

var m = moment.utc(req.body.date + ' ' + req.body.time, "YYYY-MM-DD  HH:mm:ss");
var isvalid = m.isValid();
var isafter = m.isAfter('2014-03-24T01:14:00Z');
Answer from Matt Johnson-Pint on Stack Overflow
Top answer
1 of 10
708

I believe you are looking for the query functions, isBefore, isSame, and isAfter.

But it's a bit difficult to tell exactly what you're attempting. Perhaps you are just looking to get the difference between the input time and the current time? If so, consider the difference function, diff. For example:

moment().diff(date_time, 'minutes')

A few other things:

  • There's an error in the first line:

      var date_time = 2013-03-24 + 'T' + 10:15:20:12 + 'Z'
    

    That's not going to work. I think you meant:

      var date_time = '2013-03-24' + 'T' + '10:15:20:12' + 'Z';
    

    Of course, you might as well:

      var date_time = '2013-03-24T10:15:20:12Z';
    
  • You're using: .tz('UTC') incorrectly. .tz belongs to moment-timezone. You don't need to use that unless you're working with other time zones, like America/Los_Angeles.

    If you want to parse a value as UTC, then use:

      moment.utc(theStringToParse)
    

    Or, if you want to parse a local value and convert it to UTC, then use:

      moment(theStringToParse).utc()
    

    Or perhaps you don't need it at all. Just because the input value is in UTC, doesn't mean you have to work in UTC throughout your function.

  • You seem to be getting the "now" instance by moment(new Date()). You can instead just use moment().

Updated

Based on your edit, I think you can just do this:

var date_time = req.body.date + 'T' + req.body.time + 'Z';
var isafter = moment(date_time).isAfter('2014-03-24T01:14:00Z');

Or, if you would like to ensure that your fields are validated to be in the correct format:

var m = moment.utc(req.body.date + ' ' + req.body.time, "YYYY-MM-DD  HH:mm:ss");
var isvalid = m.isValid();
var isafter = m.isAfter('2014-03-24T01:14:00Z');
2 of 10
324

You should be able to compare them directly.

var date = moment("2013-03-24")
var now = moment();

if (now > date) {
   // date is past
} else {
   // date is future
}

$(document).ready(function() {
  
  $('.compare').click(function(e) {
  
    var date = $('#date').val();
  
    var now = moment();
    var then = moment(date);
  
    if (now > then) {
      $('.result').text('Date is past');
    } else {
      $('.result').text('Date is future');
    }

  });

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>



<input type="text" name="date" id="date" value="2014-12-18"  placeholder="yyyy-mm-dd">
<button class="compare">Compare date to current date</button>
<br>
<div class="result"></div>

🌐
Moment.js
momentjs.com › docs
Moment.js | Docs
Display Format Time from now Time from X Time to now Time to X Calendar Time Difference Unix Timestamp (milliseconds) Unix Timestamp (seconds) Days in Month As Javascript Date As Array As JSON As ISO 8601 String As Object As String Inspect · Query Is Before Is Same Is After Is Same or Before Is Same or After Is Between Is Daylight Saving Time Is DST Shifted Is Leap Year Is a Moment Is a Date
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-compare-dates-with-momentjs
How to Compare Dates with Moment.js? - GeeksforGeeks
July 23, 2025 - With Moment.js, you can use methods like isBefore, isAfter, diff, and isSame to compare dates
🌐
Educative
educative.io › answers › how-to-compare-dates-with-date-object-and-momentjs-in-javascript
How to compare dates with Date object and Moment.js in JavaScript
Line 4: We use the moment object, add a year to the current date, and then format it using the format method. After that, we compare the values and print the relevant output.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-date-comparison-how-to-compare-dates-in-js
JavaScript Date Comparison – How to Compare Dates in JS
November 7, 2024 - The date object allows us to perform comparisons using the >, <, =, or >= comparison operators, but not the equality comparison operators like ==, !=, ===, and !== (unless we attach date methods to the date Object).
🌐
Medium
sixth-density-jg.medium.com › how-to-compare-dates-with-moment-js-a69be9a0effa
How to Compare Dates with Moment.js | by Jay Gao | Medium
February 24, 2023 - // Create two Moment.js objects representing dates const date1 = moment('2022-05-30'); const date2 = moment('2022-06-01'); // Compare the two dates const diffInDays = date2.diff(date1, 'days'); // returns 2 if (diffInDays > 0) { console.log('date2 is after date1'); } else if (diffInDays < 0) { console.log('date2 is before date1'); } else { console.log('date1 and date2 are the same'); }
🌐
Plain English
plainenglish.io › home › blog › javascript › how to compare only dates in moment.js
How to Compare Only Dates in Moment.js
February 16, 2023 - There’s also the isSameOrAfter method that takes the same arguments and lets us compare if one date is the same or after a given unit. ... const isSameOrAfter = moment("2010-10-20").isSameOrAfter("2010-01-01", "year"); console.log(isSameOrAfter);
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
December 8, 2025 - JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects encapsulate an integral number that represents milliseconds since the midnight at the beginning of January 1, 1970, UTC (the epoch).
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-compare-only-date-in-momentjs
How To Compare Only Date In Moment.js? - GeeksforGeeks
July 23, 2025 - This method focuses on the date part of each moment object, ignoring any differences in time. By comparing using 'day', it determines if both dates fall on the same calendar day, which makes sure that only the date is considered in the comparison.
🌐
GitHub
github.com › moment › moment › issues › 3568
Only want to compare TIME values MomentJS · Issue #3568 · moment/moment
November 5, 2016 - var currentTime= moment(); // e.g. 11:00 pm var startTime = moment('06:30 pm', "HH:mm a"); var endTime = moment('03:30 am', "HH:mm a"); amIBetween = currentTime.isBetween(startTime , endTime); console.log(amIBetween); // returns false. if date ignored I expect TRUE
Author   rfossella
🌐
Moment.js
momentjs.com
Moment.js | Home
moment("20111031", "YYYYMMDD").fromNow(); moment("20120620", "YYYYMMDD").fromNow(); moment().startOf('day').fromNow(); moment().endOf('day').fromNow(); moment().startOf('hour').fromNow();
🌐
SitePoint
sitepoint.com › blog › javascript › managing dates and times using moment.js
Managing Dates and Times Using Moment.js — SitePoint
November 7, 2024 - It allows you to parse, validate, manipulate, and display dates and times using a clean and concise API. In this article I’ll show you how to get up and running with Moment.js, as well as demonstrate several of its common use cases.
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-compare-only-dates-in-moment-js-e2421ced3318
How to Compare Only Dates in Moment.js | by John Au-Yeung | JavaScript in Plain English
July 19, 2024 - There’s also the isSameOrAfter method that takes the same arguments and lets us compare if one date is the same or after a given unit. ... const isSameOrAfter = moment('2010-10-20').isSameOrAfter('2010-01-01', 'year'); console.log(isSameOrAfter)
🌐
Moment.js
momentjs.com › guides
Moment.js | Guides
In Moment.js time math assumes a linear time scale, just incrementing or decrementing the UTC-based timestamp by the amount of the time units provided. Date math does not use a linear time scale, but rather increments or decrements the dates on the calendar. This is because the amount of time ...
🌐
DEV Community
dev.to › clarkj99 › js-date-vs-moment-js-a-really-simple-comparison-2lo4
JS Date vs Moment.js: A Really Simple Comparison - DEV Community
June 15, 2020 - function calendarDays(day) { const days = [] day.date(1) day.add(-(day.day() + 1), "d") for (let i = 1; i <= 42; i++) { day.add(1, "d") days[i] = { day: day.date(), month: day.month() } } return days } The function is called from the component and the array rendered using using the following code: {calendarDays(moment()).map(day => <span key={day.day} className="calendar-day">{day.day}</span>)}
🌐
Flexiple
flexiple.com › javascript › javascript-date-comparison-methods
JavaScript Date Comparison – How to Compare Dates in JS - Flexiple
May 7, 2024 - For exact date comparisons, using === or == with Date objects checks for object reference equality, not date equality. To accurately check if two dates represent the same moment in time, use the getTime() method:
🌐
GitHub
github.com › moment › moment
Moment.js
Parse, validate, manipulate, and display dates in javascript. - moment/moment
Starred by 48K users
Forked by 7K users
Languages   JavaScript
🌐
CoreUI
coreui.io › blog › how-to-compare-dates-with-javascript
How to compare dates with JavaScript · CoreUI
January 23, 2024 - To ensure robust and error-free date comparison in JavaScript, adopt these best practices: Use Libraries When Necessary: Utilizing libraries like Moment.js or Date-fns can simplify date manipulations and comparisons by handling edge cases and timezones effectively.
🌐
LogRocket
blog.logrocket.com › home › 5 alternatives to moment.js for internationalizing dates
5 alternatives to Moment.js for internationalizing dates - LogRocket Blog
January 17, 2025 - Moment.js is a well-established library for date processing, but it can be excessive for smaller or simpler projects. In this article, I’ve compared how five popular libraries approach date formatting in the context of internationalization.