When I was working on a TypeScript project recently, I needed to calculate dates a few days ahead, like setting deadlines or scheduling reminders. At first, I wasn’t sure how to easily add days to a date without messing up the original date or dealing with complex date math.
To solve this, I created a function that copies the original date and adds the desired number of days using built-in TypeScript date methods.
In this blog, I’ll explain how to add days to a date in TypeScript. You’ll learn how to create a reusable function that handles date calculations correctly, so you can efficiently work with future or past dates in your TypeScript projects.
Understanding the Date Object in TypeScript
To work with dates in TypeScript, we utilize the built-in Date object. The Date object represents a specific moment in time and provides various methods to manipulate and retrieve date and time values. It allows us to perform operations such as adding days, months, or years to a given date.
Check out: Get the Day of the Month in TypeScript
Adding Days to a Date Using the setDate() Method
The easiest way to add days to a date in TypeScript is by leveraging the setDate() method of the Date object. Here’s an example:
function addDays(date: Date, days: number): Date {
const result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}In this code snippet, we define a function called addDays that takes two parameters: date (of type Date) and days (of type number). Inside the function, we use the setDate() method to modify the date by adding the specified number of days.
The getDate() method retrieves the day of the month for the given date, and we simply add the desired number of days to it. Finally, we return the updated date.
Here’s how you can use the addDays function:
const currentDate = new Date("2025-06-10");
const newDate = addDays(currentDate, 5);
console.log(newDate); // Output: 2025-06-15T00:00:00.000ZOutput:

In this example, we create a Date object representing June 10, 2025. We then call the addDays function, passing the currentDate and the number of days we want to add (in this case, 5). The function returns a new Date object with the added days, which is June 15, 2025.
Check out: Get the Current Date in TypeScript
Handling Edge Cases and Considerations
When adding days to a date, there are a few edge cases and considerations to keep in mind:
- Month and Year Rollover: If the resulting day exceeds the number of days in the current month, the date will automatically roll over to the next month or even the next year. For example, adding 31 days to March 31 will result in May 1.
- Daylight Saving Time (DST): When adding days to a date, be aware of potential DST changes. If the resulting date falls within a different DST period, the time may be adjusted accordingly. It’s important to consider this if your application deals with precise timing or scheduling.
- Immutability: Keep in mind that the setDate() method modifies the original Date object. If you need to preserve the original date, make sure to create a copy of the Date object before making any modifications.
Schedule Future Events by Adding Days in TypeScript
Let’s consider a real-world scenario where adding days to a date is useful. Suppose you are building an event scheduling application for a company based in New York. The application allows users to create events and schedule them for future dates.
Here’s an example of how you can utilize the addDays function to schedule an event:
Check out: Set a Date Value to Null in TypeScript
function scheduleEvent(eventDate: Date, daysToAdd: number): void {
const futureDate = addDays(eventDate, daysToAdd);
console.log(`The event is scheduled for ${futureDate.toDateString()}`);
}
const eventDate = new Date("2025-07-04"); // Independence Day
scheduleEvent(eventDate, 7);
// Output: The event is scheduled for Fri Jul 11 2025Output:

In this example, we have a function called scheduleEvent that takes an eventDate and the number of daysToAdd. We use the addDays function to calculate the future date by adding the specified number of days to the event date. Finally, we log a message indicating when the event is scheduled.
By utilizing the addDays function, you can easily calculate and display future event dates in your application, providing a seamless user experience for scheduling events.
Conclusion
In this tutorial, we learned how to add days to a date in TypeScript using a function that keeps the original date unchanged. By creating a new Date object and using the built-in setDate() method, you can easily calculate future or past dates.
Whether you need to set deadlines or reminders, this method helps you work with dates simply and correctly. Now you can add days to any date in your TypeScript projects without facing any issues in getting the desired date, such as future dates.
You may like to read:
- Calculate Yesterday’s Date in TypeScript
- Add Months to a Date in TypeScript
- Subtract Dates in TypeScript
- Subtract Days From a Date in TypeScript

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.