Skip to content

How to Add Days to JavaScript Date

JavaScript provides the Date object, which enables you to view and manipulate date and time. Developers work with date and time frequently and often want to add some days to an existing date object. For example, consider the situation you want to show a deadline. You want to show the client that the deadline is five days after this day. In this tutorial, you will learn an easy way of adding days to JavaScript Date with setDate() and getDate() inbuilt functions to set and get the day of the month represented by the Date object.

Here is a utility function that creates a date object and adds seven days to it, to have a date object representing next week.

JavaScript create a Date copy

Output appears here after Run.

Date Object

The Date is a built-in object in JavaScript. When you create a Date object with the new Date(), a set of methods become available to operate on it. These methods allow getting and setting the year, month, day, hour, minute, second, and millisecond using local time or UTC. According to the ECMAScript standard, the Date object should represent any date and time to millisecond precision and within 100 million days before or after 1970. Note that setDate() automatically handles month and year rollovers, so passing a value beyond the current month's days will correctly advance to the next month or year.

Dual-run preview — compare with live Symfony routes.