Programming Tutorials

JavaScript: Add Days to a Date
While working with dates in JavaScript, we often need to change the dates, like adding or subtracting days to date before processing it. While adding days to a date, we expect the month and year values to be incremented accordingly depending on the number of days being added. This article will discuss practical ways to add days to a javascript date.
Add Days to a Date Value using setDate()
According to the local time, Javascript’s setDate() will set the day of the month of the specified Date instance.
Javascript’s getDate() will get the particular day of the month as per the specified date according to local time.
Add three days to today’s date
- Sort Array of Objects by String Property Value in Javascript
- Get a Random Value from Array in JavaScript
Explanation:-
- We first get today’s date from the system using the new Date() .
- Access the current day of the month using the getDate() method.
- The new v alue of the day of the month is set in the setDate() method. The arguments passed in this method are the date value received in the previous step and the number of days we want to increase (3 in our case). If the value of month and year needs to be updated, they are incremented accordingly by the setDate() method.
- Finally, the Date() constructor creates a new date with the day, month, and year values decided by the number of days being added.
Add Days to a Date Value using setTime()
Javascript’s setTime() will set the Date object to the time represented by the milliseconds since January 1, 1970, 00:00:00
Javascript’s getTime() will get the numbe r of milliseconds since ECMASCRIPT epoch
- We first get today’s dat e from the system using the new Date() .
- Access the number of milliseconds representing a particular date with the method getTime() .
- In the variable addMilliseconds , we add the number of milliseconds received in the above step and the milliseconds’ value for the number of days (_noOfDays * 24 * 60 * 60 * 1000) we wish to add in a particular date.
- The addMilliseconds variable value is then passed as an argument to method setTime(). If the value of month and year needs to be updated, they are incremented accordingly by the setTime() method.
- Finally, the Date() constructor creates a ne w date.
Add Days to a Date Value by Accessing Properties of a Date
Javascript’s getFullYear() method will return the year of the date specified according to the local time .
Javascript’s getMonth() method will return the mon th of the date specified according to the local time . The month value is zero-based that is zero indicates the first month of the year.
Javascript’s getDate() method will return the day of the month of the date specified according to the local time .
Javascript’s toDateString() method will return the portion of Date in English in the format:
- First four letters for the day of the weekday .
- First three letters of the month’s name.
- Two digits of the day of the month .
- Four digits for the year .
- We first get today’s date from the system using the new Date() .
- Then we access different properties of the date.
- getFullYear() method gets the year from today’s date.
- getMonth() method receives the current month from today’s date.
- getDate() method receives the day from today’s date.
- After accessing all the above values, create a new date by Date() constructor, which sets the value of the day, month, and year based on how many days we are adding to the current date.
I hope this article helped you add the number of days to a javascript date. Good Luck !!!
Related posts:
- Check if two NumPy Arrays are equal in Python
- Get Column Index from Column Name in Pandas DataFrame
- Finding all values for a key in multimap using equals_range – Example
- 3 ways to skip first 10 results
- How to Add / Subtract Days, Months or Years from a Date in C++
- Add days to a date in Python
- Add elements to the end of Array in Python
- DROP multiple columns in MySQL with single ALTER statement
- How to Convert String to Date in C++ using Boost Library
- How to disable foreign key constraint in MySQL
Leave a Comment Cancel Reply
Your email address will not be published. Required fields are marked *
This site uses Akismet to reduce spam. Learn how your comment data is processed .
Advertisements
To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.
How to add days to a date in JavaScript
Please enable JavaScript
To add seven days to a Date object, use the following code:
✌️ Like this article? Follow me on Twitter and LinkedIn . You can also subscribe to RSS Feed .
You might also like...
Buy me a coffee ☕, ✨ learn to build modern web applications using javascript and spring boot.
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How to add days to today? javascript
How to add days to today in day-month-year format? I tried this code but additionally get the time zone and month in the short word name. I want to receive, for example, August 12, 2023 here is the code:
Date.prototype.addDays = function(days) { var date = new Date(this.valueOf()); date.setDate(date.getDate() + days); return date; } var date = new Date(); console.log(date.addDays(5));
- Already answered here: stackoverflow.com/questions/1197928/… – aggregate1166877 Jul 10, 2022 at 11:23
- Does this answer your question? How do I format a date in JavaScript? – Muhammad Khuzaima Umair Jul 10, 2022 at 11:30
4 Answers 4
To get the format: Month Day, Year , Simply use ECMAScript Internationalization API :
Note: 'long' uses the full name of the month, 'short' for the short name,

Create an array of months
In the function Date.prototype.addDays , return the date string as

Your question is twofold:
- how to add days to a date
- and how to format a date
1. adding days
the easiest way to do simple calculations with date and time values is to transform all date and time into UNIX timestamps (number of milliseconds since the january 1st 1970 epoch) then adding and substracting days or calculating date differences is simply adding and substracting integer numbers.
For example.
to obtain the unix time of right now just use Date.now() which is 1657452836534 five days in millisecods is 5*24*60*60*1000 thus five days ahead of now is Date.now() + 5*24*60*60*1000 which is 1657884836534 to obtain a Date object, you need to create one with the timestamp value new Date(Date.now() + 5*24*60*60*1000)
2. format Date
formatting Dates is more complex that it seems, as there are some subtle issues around, depending on users cultural conventions. See How do I format a date in JavaScript? for a detailed answer. But as a show answer if you want your code to work for any user, the easiest way it to use native javascript toLocaleDateString() function. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString .
wrapping up, for your case, try

You are adding 2 dates in the correct way, there is the only problem in outputting the date in desired format. You can format the date as follow based on this answer :
Date.prototype.addDays = function(days) { var date = new Date(this.valueOf()); date.setDate(date.getDate() + days); // return formatted date var options = {year: 'numeric', month: 'long', day: 'numeric' }; return date.toLocaleDateString("en-US", options); } var date = new Date(); console.log(date.addDays(5));
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged javascript or ask your own question .
- The Overflow Blog
- How Intuit democratizes AI development across teams through reusability sponsored post
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
Hot Network Questions
- What is temperature in the classical entropy definition?
- How should I go about getting parts for this bike?
- Drywall repair - trying to match texture
- Why is there a voltage on my HDMI and coaxial cables?
- Disconnect between goals and daily tasks...Is it me, or the industry?
- Linear regulator thermal information missing in datasheet
- Follow Up: struct sockaddr storage initialization by network format-string
- Does melting sea ices rises global sea level?
- For the Nozomi from Shinagawa to Osaka, say on a Saturday afternoon, would tickets/seats typically be available - or would you need to book?
- Why did Windows 3.0 fail in Japan?
- Lagrange Points in General Relativity
- Imtiaz Germain Primes
- Why do small African island nations perform better than African continental nations, considering democracy and human development?
- Randomly offset duplicate points along a linestring x meters using PostGIS
- Why do many companies reject expired SSL certificates as bugs in bug bounties?
- How do/should administrators estimate the cost of producing an online introductory mathematics class?
- Why can't I defun "nil" as a function name
- What is the name of the color used by the SBB (Swiss Federal Railway) in the 1920s to paint their locomotive?
- Equation alignment in aligned environment not working properly
- Why Chandrasekhar in 1931 used 2.5 for molecular weight?
- Are there tables of wastage rates for different fruit and veg?
- How can I check before my flight that the cloud separation requirements in VFR flight rules are met?
- Euler: “A baby on his lap, a cat on his back — that’s how he wrote his immortal works” (origin?)
- Align vertically 2 circuits
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
Get my latest tutorials
Related tutorials, how to add days to a date in javascript.
In this tutorial, we are going to learn about how to add days to the current date in JavaScript using the new Date() constructor.
Adding days to current Date
- To add the days to a current date, first we need to access it inside the JavaScript using the new Date() constructor .
- Now, we can add the required number of days to a current date using the combination of setDate() and getDate() methods.
Full example:
Definitions
- The setDate() method sets the day of the month to a Date object.
- The getDate() method gets the current day of the month (from 1 - 31).

Top tutorials
Css tutorials & demos, how rotate an image continuously in css.
In this demo, we are going to learn about how to rotate an image continuously using the css animations.
How to create a Instagram login Page
In this demo, i will show you how to create a instagram login page using html and css.
How to create a pulse animation in CSS
In this demo, i will show you how to create a pulse animation using css.
Creating a snowfall animation using css and JavaScript
In this demo, i will show you how to create a snow fall animation using css and JavaScript.
Top Udemy Courses

JavaScript - The Complete Guide 2022 (Beginner + Advanced)

React - The Complete Guide (incl Hooks, React Router, Redux)

Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Start with a boilerplate:
- React + JSX
- CoffeeScript
- 👍🏻 Roadmap (vote for features)
- 🐞 Bug tracker
- 🎛 Service status
JSFiddle is for:
- Adopting CSS Grid at scale via julian.is
- Show MDN browser compatibility data on the command line via changelog.com
- 🙋 Suggest a link
- Demos for docs
- Bug reporting (test-case) for Github Issues
- Presenting code answers on Stack Overflow
- Live code collaboration
- Code snippets hosting
- ... or just your humble code playground ✌🏻
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Online javascript editor, testing javascript online, online ide, online code editor, html, css, coffeescript, scss online editor, editor layout.
Console in the editor (beta)
Clear console on run
Line numbers
Indent with tabs
Code hinting (autocomplete) (beta)
Auto-run code
Only auto-run code that validates
Auto-save code (bumps the version)
Auto-close HTML tags
Auto-close brackets
Live code validation
Highlight matching tags
Boilerplates
Show boilerplates bar less often
Save anonymous (public) fiddle?
- Be sure not to include personal data - Do not include copyrighted material
Log in if you'd like to delete this fiddle in the future.
Fork anonymous (public) fiddle?
Embed snippet Prefer iframe? :
No autoresizing to fit the code
Render blocking of the parent page
Fiddle meta
[Demo] Add Days to a Date in JavaScript
Private fiddle Extra
Groups Extra
Resources url cdnjs 2.
- jquery-ui.js Remove
- jquery-ui.css Remove
- Paste a direct CSS/JS URL
- Type a library name to fetch from CDNJS
Async requests
/echo simulates Async calls: JSON: /echo/json/ JSONP: //jsfiddle.net/echo/jsonp/ HTML: /echo/html/ XML: /echo/xml/
See docs for more info.
Other (links, license)
Created and maintained by Piotr and Oskar .
Hosted on DigitalOcean
All code belongs to the poster and no license is enforced. JSFiddle or its authors are not responsible or liable for any loss or damage of any kind during the usage of provided code.
Bug tracker Roadmap (vote for features) About Docs Service status
Support the development of JSFiddle and get extra features ✌🏻
We'll always be free, but for our loyal users we also have some additional stuff:
Frameworks & Extensions
- jQuery Mobile 1.4.4
Framework <script> attribute
Normalized CSS

IMAGES
VIDEO
COMMENTS
According to the local time, Javascript's setDate() will set the day of the month of the specified Date instance. Javascript's getDate() will get the particular day of the month as per the specified date according to local time
To add days to a date in JavaScript. For example, to add one day to the current date, use the following code. To update an existing JavaScript Date object, you can do the following
Add days to javascript date - JavaScript provides the Date object for manipulating date and time. In between the various methods of the Date object, will be focusing in this post are the setDate(value) and
The Date is a built-in object in JavaScript. Once a Date object is created with the New Date(), a set of methods become available to operate on it. These methods allow getting and setting the year
To get the format: Month Day, Year, Simply use ECMAScript Internationalization API. the easiest way to do simple calculations with date and time values is to transform all date and time into UNIX timestamps
To add the days to a current date, first we need to access it inside the JavaScript using the new Date() constructor. const current = new Date ( ) ;Now, we can add the required number of days to a current date
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor. Then click the Button to see how 3 days is added to this Date and shown in "Follow Date" TextBox. </ h2 >