A few simple yet really effective ways to add days will be discussed. Letís check out the methods
Get current day using getDate()
To get the day of the month, you need to call getDate() after setting up a new date with Date(). When you call the console, you get the output.:
Add 1 day to the current date
To add 1 day to it, you just need the same procedure, but as you are adding a day to the current date, just add 1 at the end of the getDate(). After calling the console log, you get the output.
To set the day, use setDate(). Add a number to the set.
Add 7 days to current days
The code remains the same, you just need to add the days to the current date. The process is the same as above, but you just need to add +7 when using setDate(), but before that, use the getDate() With +7. You get the output with 7 days added to the current day.
Add 4 Months to a date
To add months to date, you can either add 120 days, which is equal to 4 months, or add months. You can do this using getMonth() and setMonth().
It enables the function in the package moment. This function works really well as it creates dates object along with providing many methods and properties. To add days, moment.js has add() and format() methods. When you get the console log, it displays month, date, and year.
Another way to try adding days to date is to use an external library like day.js. It is a lightweight library that is easy to use. First, install the library using npm install for daysjs.
But before that, you need to make sure you initialize your node project to use day.js with the help of init -y command.
In the day.js library, you require to use the dayjs package to import the function. By default, the function uses the current date and time for object creation, so if you need to use a specific date, you need to create a date object