
- 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
How to set the day of a date in JavaScript?
Following is the code to set the day of a date 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; } </style> </head> <body> <h1>Setting day of the date in JavaScript</h1> <div class="sample"></div> <div style="color: green;" class="result"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to change the day of the above date object </h3> <script> let sampleEle = document.querySelector('.sample'); let resEle = document.querySelector(".result"); let dateObj = new Date(); sampleEle.innerHTML = dateObj; document.querySelector(".Btn").addEventListener("click", () => { dateObj.setDate(28) resEle.innerHTML = 'Changing day of the date = <br> '+dateObj; }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Set the day of the month for a specified date according to universal time?
- Finding day of week from date (day, month, year) in JavaScript
- How to add a day to the date in MySQL?
- JavaScript program to decrement a date by 1 day
- How to set cookies expiry date in JavaScript?
- Java Program to return a Date set to noon to the closest possible millisecond of the day
- Java Program to return a Date set to the last possible millisecond of the day before midnight
- Java Program to return a Date set to the first possible millisecond of the day after midnight
- How to use date command in day to day practical usage
- How to add 1 day to the date in MySQL?
- How to display first day and last day of the month from date records in MySQL?
- Finding the nth day from today - JavaScript (JS Date)
- How to add 1 day to a Date in iOS/iPhone?
- How add 1 day to Date in swift?
- How to set JavaScript Cookie with no expiration date?

Advertisements