How To Get Previous Year Date Using JavaScript?
Nov 27, 2021 . Admin
Hello Friends,
Now let's see example of how to get previous year date example.We will check how to get previous year date. This is a short guide on get previous year date in javascript. Here you will learn how to get javascript previous year date. Let's get started with how to get previous year date in javascript.
Here i will give you many example how to get previous year 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 Previous Year Date Using JavaScript? - MyWebtuts.com</title> </head> <body> <h3>How To Get Previous Year Date Using JavaScript? - MyWebtuts.com</h3> <script type="text/javascript"> var prevYearDate = new Date(new Date().getFullYear(), 0, 1); prevYearDate.setFullYear(prevYearDate.getFullYear()-1); var getDate = prevYearDate.toLocaleString('en-US'); document.write(getDate); </script> </body> </html>Output :
1/1/2020, 12:00:00 AMExample : 2
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>How To Get Previous Year Date Using JavaScript? - MyWebtuts.com</title> </head> <body> <h3>How To Get Previous Year Date Using JavaScript? - MyWebtuts.com</h3> <script type="text/javascript"> var previousYearDate = new Date(new Date().getFullYear() -1, 0, 1); var getDate = previousYearDate.toLocaleString('en-US'); document.write(getDate); </script> </body> </html>Output :
1/1/2020, 12:00:00 AM
It will help you...