Add 5 days to a string

I have this string
var start = $(‘[name=invoicedate]’).val();
alert(‘start’); // 2010/01/01

how can I add five days to have the following?
alert(‘start’); // 2010/01/10

Tried
var start = new Date(year, month, day+5);
but seems not work

  1. Create a date.
  2. Add five days
  3. Profit???

Assuming that $(‘[name=invoicedate]’).val() is the string ‘2010/01/01’, you can create a date using that string with:

var start = new Date($('[name=invoicedate]').val());

Then you can use the getDate and setDate methods to add 5 days to it with:

start.setDate(start.getDate() + 5);

resulting in the following code:


var start = new Date($('[name=invoicedate]').val());
start.setDate(start.getDate() + 5);

If you want to retrieve just the date portion so you can display it elsewhere, you can use the toDateString method

var date = start.toDateString()
// Wed Jan 06 1010

Or, if you want to format it in some special way, you can use getDate, getMonth (which starts at 0) and getFullYear

var date = start.getFullYear() + '/' + (start.getMonth() + 1) + '/' + start.getDate();
// 2010/01/06

Hi Paul,

Thanks for your reply and attention.
Just want to ask something

var start = new Date($(‘[name=invoicedate]’).val());
start.setDate(start.getDate() + 5);
Until here it works perfect, it adds five days

but this does not give me a string
var date = start.getFullYear() + ‘/’ + (start.getFullMonth + 1) + ‘/’ + start.getDate; // 2010/01/06
alert(date);
// 2011/NaN/function getDate(){ [native code] } ??

I should test before showing such code.

Instead of getFullMonth it’s getMonth(), and instead of getDate it’s getDate()


var date = start.getFullYear() + '/' + (start.getMonth() + 1) + '/' + start.getDate(); // 2010/01/06

I’ll update the initial post as well.