This is just regular JavaScript, no need for TypeScript.

CopyyourDate = new Date(yourDate.getTime() + (1000 * 60 * 60 * 24));

1000 milliseconds in a second * 60 seconds in a minute * 60 minutes in an hour * 24 hours.

Additionally you could increment the date:

CopyyourDate.setDate(yourDate.getDate() + 1);

The neat thing about setDate is that if your date is out-of-range for the month, it will still correctly update the date (January 32 -> February 1).

See more documentation on setDate on MDN.

Answer from Adam on Stack Overflow
🌐
SPGuides
spguides.com › typescript-date-add-days
How to Add Days to Date in Typescript [With 6 Examples]
November 20, 2023 - The output, after I ran the code using Visual Studio Code, is shown in the screenshot below: It adds 5 days to the current date in Typescript.
🌐
Dirask
dirask.com › posts › TypeScript-add-days-to-date-pJAaVD
TypeScript - add days to date
In this example, we create a simple function that takes two arguments: ... const addDays = (date: Date, days: number): Date => { let result = new Date(date); result.setDate(result.getDate() + days); return result; }; // Usage example: const ...
🌐
ReactHustle
reacthustle.com › blog › how-to-add-days-to-a-date-object-in-javascript-typescript
How to Add Days to a Date Object in Javascript (Typescript) | ReactHustle
Date.prototype.addDays = function ...addDays(3)) // Sun Jan 15 2023 00:00:00 ... For Typescript, you have to extend the Date interface in the global scope....
🌐
HowToDoInJava
howtodoinjava.com › home › typescript › typescript date
TypeScript Date (with Examples)
August 29, 2023 - We can modify a Date object using its set() methods for the specific date and time parts. For example, we can add days to a Date using the setDate() method.
🌐
TutorialsPoint
tutorialspoint.com › home › typescript › typescript date object
Understanding TypeScript Date Object
December 18, 2016 - Next, we have passed the date in the string format as a parameter of the Date() constructor, and it returns a new date according to the date string. Next, we have passed year, month, day, etc.
🌐
Linux Hint
linuxhint.com › add-days-to-date-in-typescript
How to Add Days to Date in TypeScript
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
Find elsewhere
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-add-days-to-current-date-in-javascript.php
How to Add Days to Current Date in JavaScript
// Specific date var date = new Date('August 21, 2021 16:45:30'); // Add ten days to specified date date.setDate(date.getDate() + 10); console.log(date);
🌐
Learn TypeScript
learntypescript.dev › 03 › l1-dates
Using the Date type | Learn TypeScript
If we assign a variable to the JavaScript Date constructor, TypeScript infers its type to be Date. The Date type is a representation of the Date object in JavaScript. Enter the following code into the editor beneath the dateOfBirth declaration. Manually type the code rather than copying and pasting. ... Notice how the editor provides intellisense. ... Type annotations can be used for dates as well. ... Add type annotations to the function so that startDate is a Date, and the function return type is also Date.
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-days-to-date-in-javascript
How to Add Days to Date in JavaScript? - GeeksforGeeks
July 23, 2025 - The 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 ...
🌐
Code with Hugo
codewithhugo.com › add-date-days-js
Add days to a Date in vanilla JavaScript · Code with Hugo
May 1, 2020 - const d = new Date('2019-04-14'); const monthRollsOver = addDays(myDate, 31); console.log(monthsRollOver) // 2019-05-15 · Find the live examples at: observablehq.com/@hugodf/add-days-to-a-javascript-date
🌐
The Valley of Code
thevalleyofcode.com › how-to-add-days-date-javascript
How to add days to a date in JavaScript
Here is a date that represents today: const my_date = new Date() Suppose we want to get the date that’s “30 days from now”. We use the setDate() and getDate() methods, in this way: my_date.setDate(my_date.getDate() + 30) Want to master ...
🌐
Reddit
reddit.com › r/typescript › handle dates
r/typescript on Reddit: Handle dates
August 20, 2020 -

Handle dates

Does anyone have a good helper function to handle dates in JavaScript/typescript?

For example if the date is 2020-09-27 and you want to add 7 days to the date it updates correctly. Should be 2020-09-04 after adding 7 days .

Thank you for the help

🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › date-add-days
JavaScript Add Days to Date - Mastering JS
const date = new Date('2022-06-01'); // June 1, 2022 UTC time date.setDate(date.getDate() + 30); // Add 30 days date; // July 1, 2022 UTC time · The setDate() function modifies the date object in-place and returns the new Unix timestamp as a number.
🌐
Reddit
reddit.com › r/javascript › [askjs] is it not allowed to extend the date class in typescript/javascript by adding methods?
r/javascript on Reddit: [AskJS] Is it not allowed to extend the Date class in TypeScript/JavaScript by adding methods?
November 11, 2024 -

For example, consider the following implementation:

Date.prototype.isBefore = function(date: Date): boolean {
  return this.getTime() < date.getTime();
};

With this, you can compare dates using the following interface:

const date1 = new Date('2021-01-01');
const date2 = new Date('2021-01-02');
console.log(date1.isBefore(date2)); // true

Is there any problem with such an extension?

There are several libraries that make it easier to handle dates in JavaScript/TypeScript, but major ones seem to avoid such extensions. (Examples: day.js, date-fns, luxon)

Personally, I think it would be good to have a library that adds convenient methods to the standard Date, like ActiveSupport in Ruby on Rails. If there isn't one, I think it might be good to create one myself. Is there any problem with this?

Added on 2024/11/12:

Thank you for all the comments.

It has been pointed out that such extensions should be avoided because they can cause significant problems if the added methods conflict with future standard libraries (there have been such problems in the past).

Top answer
1 of 18
54
Don’t do this. If other libraries also modify the same prototype with methods with the same name but different signature or behavior it breaks things. If the platform later on wants to add those convenience methods natively, it will break things. You can look up squooshgate for an example of this being an issue. https://developer.chrome.com/blog/smooshgate
2 of 18
22
Usually everyone agrees that you should not extend (and especially override) global scope, and all the things that make part of it like Date or Number (you can use them anywhere). I say extend whatever you want if you don't expect any third party code interference, but if you do have some dependencies or want to be a dependency for someone (be a package) then you may create problems. Javascript has many ways of customization, and the only reason everybody is stuck with the same code is because of either community interop, or older browser support (can't even do private class fields cause they are from ES2022). P.s. if you really want custom behavior you can do several things: declare a new const Date at the top of your ES module and don't export it. declare a new const Date in an ifee, or void(/*code here*/) if you don't need to return anything. and the most potentially breaking one: add something to the global Date via Date.., either way don't touch the prototype for 2 reasons it kind of messes up engine optimisations it extends to javascript "primitives", if you extend a Number prototype then you affect even primitive numbers, for example you could overwite Number.prototype.toString() so that all stringified numbers equal "69", i.e. (342).toString() === "69" // true
🌐
Medium
medium.com › @gaelgthomas › add-one-day-to-date-in-javascript-6b7d98b0edce
Add One Day to Date in JavaScript | by Gaël Thomas | Medium
December 21, 2022 - The best way to add 1 day to a JavaScript date is by using the Date object. On an existing Date, you can use the getDate function to get the day (between 1 and 31), add 1 to this number, then use…