How To Check Date Is Greater Than Today In JavaScript?


Share:
 | Published By: Admin | Published On: Dec 04, 2021 | Category: Javascript


Hello Friends,

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

Here i will give you many example how to check date is greater 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 Greater Than Today In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Check Date Is Greater Than Today In JavaScript? - MyWebtuts.com</h3>

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

        <script type="text/javascript">

            var GivenDate = '2022-02-22';
            var CurrentDate = new Date();
            GivenDate = new Date(GivenDate);

            if(GivenDate > CurrentDate){
                document.write('Given date is greater than the current date.');
            }
            else
            {
                document.write('Given date is not greater than the current date.');
            }
            
        </script>
    </body>
</html>
Output :
Given date is greater 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 Greater Than Today In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Check Date Is Greater Than Today In JavaScript? - MyWebtuts.com</h3>

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

        <script type="text/javascript">

            var specific_date = new Date('2017-03-26');
            var current_date = new Date();
            
            if(current_date.getTime() > specific_date.getTime()){
                document.write('Current Date is Grater Than Specific Date')
            }else{
                document.write('Current Date is Lower Than Specific Date')
            }
            
        </script>
    </body>
</html>
Output :
Current Date is Grater Than Specific Date

It will help you...

Share: