How To Get Next Sunday Date In JavaScript?

Dec 09, 2021 . Admin



Hello Friends,

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

Here i will give you many example how to get next sunday date 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 Get Next Sunday Date In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Get Next Sunday Date In JavaScript? - MyWebtuts.com</h3>

        <script type="text/javascript">

            function nextDate(dayIndex) {
                var today = new Date();
                today.setDate(today.getDate() + (dayIndex - 1 - today.getDay() + 7) % 7 + 1);
                return today;
            }
            
            var sundayDt = nextDate(0).toLocaleString();

            document.write(sundayDt);

        </script>
    </body>
</html>
Output :
12/12/2021, 17:44:10
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>How To Get Next Sunday Date In JavaScript? - MyWebtuts.com</title>
    </head> 
    <body>  
        <h3>How To Get Next Sunday Date In JavaScript? - MyWebtuts.com</h3>

        <script type="text/javascript">

            function nextDay(x){
                var now = new Date();    
                now.setDate(now.getDate() + (x+(7-now.getDay())) % 7);
                return now;
            }
            
            var sundayDt = nextDay(0).toLocaleString();

            document.write(sundayDt);

        </script>
    </body>
</html>
Output :
12/12/2021, 17:44:53

It will help you...

#Javascript