How To Check Date Is Less Than Today In JavaScript?


Share:
Published By: Admin, Published On: Dec 07, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to check date is less than today example. We will check how to check date is less than today. This is a short guide on check date is less than today in javascript. Here you will learn how to check date is less than today. Let's get started with how to check date is less than today in javascript.

Here i will give you many example how to check date is less than today using javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>How To Check Date Is Less Than Today In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Check Date Is Less Than Today In JavaScript? - MyWebtuts.com</h3>

        <p id="demo"></p>

        <script type="text/javascript">

            var GivenDate = '2019-02-15';
            var CurrentDate = new Date();
            GivenDate = new Date(GivenDate);

            if(GivenDate < CurrentDate){
                document.write('Given date is less than the current date.');
            }else{
                document.write('Given date is not less than the current date.');
            }
            
        </script>
    </body>
</html>
Output :
Given date is less than the current date.
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>How To Check Date Is Less Than Today In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Check Date Is Less Than Today In JavaScript? - MyWebtuts.com</h3>

        <p id="demo"></p>

        <script type="text/javascript">

            var specific_date = new Date('2022-07-20');
            var current_date = new Date();
            
            if(current_date.getTime() < specific_date.getTime()){
                document.write('Current Date is Less Than Specific Date')
            }else{
                document.write('Current Date is Greater Than Specific Date')
            }
            
        </script>
    </body>
</html>
Output :
Current Date is Less Than Specific Date

It will help you...

Share: