In this tutorial, We will learn how to moment check the date is past. I am going to learn you how to check the date is past in a momentjs.


Lets learn by example:

<!DOCTYPE html>
<html>
    <head>
        <title>jquery moment example</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>
    </head>
    <body>
        <h1>jquery moment example</h1>
    </body>
    <script type="text/javascript">
        var todayDate = moment('02-01-2021', 'DD-MM-YYYY');
        var pastDate = moment('01-01-2021', 'DD-MM-YYYY');

        var dDiff = todayDate.diff(pastDate);
        if (dDiff > 0) {
            console.log('Date is not past');
        } else {
            console.log('Date is past');
        }

        var dDiff2 = pastDate.diff(todayDate);
        if (dDiff2 > 0) {
            console.log('Date is not past');
        } else {
            console.log('Date is past');
        }
    </script>
</html>


Output:

Date is not past
Date is past

Now, You have understood what is movementjs to get all dates.


Thanks, May this example will help you...