
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript program to decrement a date by 1 day
Following is the code to decrement a date by 1 day in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 20px; font-weight: 500; color: rebeccapurple; } </style> </head> <body> <h1>JavaScript program to decrement a date by 1 day</h1> <div class="sample"></div> <div style="color: green;" class="result"></div> <button class="Btn">Decrement</button> <h3>Click on the above button to decrement the date by one day</h3> <script> let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); let date = new Date(); sampleEle.innerHTML = date; document.querySelector(".Btn").addEventListener("click", () => { date.setDate(date.getDate() - 1); resEle.innerHTML = "New Date = " + date; }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘Decrement’ button −
- Related Articles
- Java Program to decrement a Date using the Calendar Class
- How add 1 day to Date in swift?
- How to add 1 day to a Date in iOS/iPhone?
- How to set the day of a date in JavaScript?
- How to add 1 day to the date in MySQL?
- C++ Program to print current Day, Date and Time
- Finding day of week from date (day, month, year) in JavaScript
- Getting tomorrow and day after tomorrow date in JavaScript
- Finding the nth day from today - JavaScript (JS Date)
- Java Program to display date with day name in short format
- How to use date command in day to day practical usage
- Increment Negative and Decrement Positive Numbers by 1 in an Array in Java
- What is decrement (--) operator in JavaScript?
- How to add a day to the date in MySQL?
- How to select rows in MySQL that are >= 1 DAY from the current date?

Advertisements