How To Check Date Is Weekend 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 weekend example. We will check how to check date is weekend. This is a short guide on check date is weekend in javascript. Here you will learn how to check date is weekend. Let's get started with how to check date is weekend in javascript.

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

        <script type="text/javascript">

            var d = new Date();
            var n = d.getDay();

            if( n == 6 ){
                document.write("Its weekend!");
            }else{
                document.write("Its not weekend");
            }
            
        </script>
    </body>
</html>
Output :
Its not weekend
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 Weekend In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Check Date Is Weekend In JavaScript? - MyWebtuts.com</h3>

        <script type="text/javascript">
            
            var givenDate = new Date('2021-12-05');
            var day = givenDate.getDay();
            var isWeekend = (day === 6) || (day === 0) ? 'This is Weekend': 'This is Working Day';
                
            document.write(isWeekend);
            
        </script>
    </body>
</html>
Output :
This is Weekend

It will help you...

Share: