How To Get Yesterday Date In JavaScript?

Nov 26, 2021 . Admin



Hello Friends,

Now let's see example of how to convert get yesterday date example. This is a short guide on get yesterday date. Let's get started with how to get yesterday date in javascript.

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

        <script type="text/javascript">
            var prev_date = new Date();
            prev_date.setDate(prev_date.getDate() - 1);
            document.write(prev_date.toLocaleString('en-US'));
        </script>
    </body>
</html> 
Output :
11/25/2021, 7:07:48 PM
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>How To Get Yesterday Date In JavaScript? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Get Yesterday Date In JavaScript? - MyWebtuts.com</h3>

        <script type="text/javascript">
            var yesterday = new Date(Date.now() - 864e5);
            document.write(yesterday.toLocaleString('en-US'));
        </script>
    </body>
</html>
Output :
11/25/2021, 7:10:00 PM

It will help you...

#Javascript