How to Add Days to Date in JavaScript? Last Updated : 13 Aug, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Adding days to a date in JavaScript is a common task when working with dates and times. This involves manipulating the Date object to calculate a future or past date by adding a specific number of days. This is useful for tasks like scheduling events, and deadlines, or simply adjusting dates dynamically within an application.There are two methods to achieve this with the Date object:Table of ContentUsing setDate() MethodUsing getTime() Method1. Using setDate() MethodThe setDate() method allows you to modify the day of the month for a Date object. To use this method, you start by creating a Date object that represents the current date. You can then add a specific number of days to this date and assign the result to a new Date object. Example: This example we defines a function addDays to add a specified number of days to a date, then applies it to the current date, and logs the new date. JavaScript // Function to Add days to current date function addDays(date, days) { const newDate = new Date(date); newDate.setDate(date.getDate() + days); return newDate; } // Get the current date const todayDate = new Date(); // Number of days that we want to add to the current date const days = 7; // Function call to add days const newDate = addDays(todayDate, days); console.log("New Date: ", newDate.toDateString()); OutputNew Date: Sun Dec 17 2023 2. Using getTime() MethodThe getTime() method in JavaScript returns the number of milliseconds elapsed since January 1, 1970. To add a specific number of days to a date, we first convert the days into milliseconds and then add them to the current date represented in milliseconds. This approach enables precise date manipulation in JavaScript.Example: This example the addDays function adds a specified number of days to a given date. It calculates the new date and returns it, then logs the updated date using toDateString(). JavaScript // Function to Add days to current date function addDays(date, days) { const newDate = new Date(date.getTime() + days * 24 * 60 * 60 * 1000); return newDate; } // Get the current date const todayDate = new Date(); // Number of days that we want to add to the current date const days = 7; // Function call to add days const newDate = addDays(todayDate, days); console.log("New Date:", newDate.toDateString()); OutputNew Date: Sun Dec 17 2023 Comment More infoAdvertise with us Next Article How to convert a JavaScript date to UTC? B blalverma92 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League javascript-date JavaScript-Questions Geeks Premier League 2023 +2 More Similar Reads How to Format a Date in JavaScript? Here are different ways to format the date in JavaScript.1. Using the toDateString() MethodThe toDateString() method formats the date object into a human-readable format as Day Month Date Year.SyntaxdateObj.toDateString();JavaScriptconst date = new Date(); const formatDate = date.toDateString(); con 2 min read How to Get the Current Date in JavaScript ? The Date() object is used to access the current date in JavaScript. To get the current date in string format, we can use toDateString() method. The date.toDateString() method converts the given date object into the date portion into a string.SyntaxdateObj.toDateString()JavaScript// Create a Date Obj 2 min read How to Log the Current Date in JavaScript ? The Date object is an inbuilt object constructor of JavaScript language. It is used to work with dates and times. The Date object is created by using the new keyword, i.e. new Date(). The current date can be logged on the console in JavaScript using the below-discussed methods. Table of Content Usin 3 min read JavaScript Adding days in milliseconds to Date object Given a date, the task is to add days in milliseconds to it using JavaScript. To add days in milliseconds to date objects in JavaScript, some methods are used which are listed below: JavaScript getMilliseconds() Method: This method returns the milliseconds (from 0 to 999) of the provided date and ti 2 min read How to convert a JavaScript date to UTC? Javascript date can be converted to UTC by using functions present in the Javascript Date object. The toUTCString() method is used to convert a Date object into a string, according to universal time. The toGMTString() returns a string that represents the Date based on the GMT (UT) time zone. By defa 1 min read How To Format JavaScript Date as yyyy-mm-dd? We use JavaScript built-in help methods from the Date class that help us to create a formatted version of the current date in the form of yyyy-mm-dd. These are the approaches used to format JavaScript date as yyyy-mm-dd.Table of ContentUsing the ISO String Method USing JavaScript Method1. Using the 2 min read Like