I want to add months to a date in JavaScript.
For example: I am inserting date 06/01/2011
(format mm/dd/yyyy
) and now I want to add 8 months to this date. I want the result to be 02/01/2012
.
So when adding months, the year may also increase.
To add days to a date in JavaScript, you can use the setDate() and getDate() methods of the Date object. These methods are used to set and get the day of the month of the Date object.
Corrected as of 25.06.2019:
var newDate = new Date(date.setMonth(date.getMonth()+8));
Old From here:
var jan312009 = new Date(2009, 0, 31); var eightMonthsFromJan312009 = jan312009.setMonth(jan312009.getMonth()+8);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With