One data grid for JavaScript, React, Vue & Angular. Sorting, filtering, virtualization, pinning, and CSV export included. Early access $199 $349 → [Get it now]

How to add days to a date in JavaScript

Adding days to a date is a common task when building modern javascript applications, especially when you need code that is easy to read and safe to reuse. As the creator of CoreUI, I usually prefer the simplest built-in approach that stays explicit in real production code. Use Date.setDate() together with Date.getDate() to add days to a JavaScript date while keeping the built-in Date API. This keeps the solution approachable while still being reliable enough for components, utilities, and data transformation logic. Below I will show the core snippet first, explain why it works, and point out the most important implementation detail to keep in mind.

Use Date.setDate() together with Date.getDate() to add days to a JavaScript date while keeping the built-in Date API.


const date = new Date('2026-05-12')
const daysToAdd = 7

const result = new Date(date)
result.setDate(result.getDate() + daysToAdd)

console.log(result.toISOString())

This approach creates a copy of the original date, reads the current day of the month, and then adds the required number of days with setDate(). JavaScript automatically handles month and year rollovers, so the same code works across month boundaries without extra calculations.

Why this works

The key detail is that setDate() updates the day-of-month value and automatically rolls over into the next month or year when needed. That means you do not need custom logic for month boundaries, leap years, or different month lengths.

Common pitfall

Do not mutate a shared date object unless that is exactly what you want. In most application code, creating a copy first with new Date(originalDate) is safer because it avoids side effects in other parts of the codebase.

Best Practice Note

This is the same kind of practical, low-complexity approach we prefer in CoreUI components to keep code predictable and easy to maintain.

If you are working on similar problems, these guides are good follow-ups:


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to create a single page application using React.js
How to create a single page application using React.js

React v18.0 – finally is of legal age?
React v18.0 – finally is of legal age?

Quo Vadis Vue.js
Quo Vadis Vue.js

Vue UI component libraries 2022
Vue UI component libraries 2022

Answers by CoreUI Core Team