Add Days to Date in JavaScript

A common requirement while working with dates in JavaScript is to add days to a date. Let us see how to do this in JavaScript

JavaScript provides the Date object for manipulating date and time. Amongst the various methods of the Date object, the one will be focusing in this post are the setDate(value) and getDate() which sets and gets the day of the month respectively.

Add Days to Date in JavaScript

title>Add Days to a Date from</title>
script type="text/javascript">
var newDt = new Date();
document.writeln("Current Date :" + newDt + "<br/>");
// add 5 days to the
current date
newDt.setDate(newDt.getDate() + 5);
document.writeln("New Date :" + newDt);

Add Days to Date

Similarly to add months, JavaScript has the setMonth(month,date) and getMonth() method and to add Years, you can use the setFullYear() and getFullYear() methods.

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal