0

I have today's date like so:

var date = new Date();

var yyyy = date.getFullYear().toString();
var mm = (date.getMonth() + 1).toString();
var dd = date.getDate().toString();

var mmChars = mm.split('');
var ddChars = dd.split('');

var datestring = yyyy + '-' + (mmChars[1] ? mm : "0" + mmChars[0]) + '-' + (ddChars[1] ? dd : "0" + ddChars[0]);

Now what I am trying to do is add 5 days to the datestring date, how would I do this?

My issue with this is, I have the date already formatted to my liking, I want to add 5 days to the already formatted date.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
user979331
  • 11,039
  • 73
  • 223
  • 418

1 Answers1

1

You could add 5 days to the original date object you have. See Date.getDate.

var date = new Date();
date.setDate(date.getDate() + 5);
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
Billy
  • 154
  • 5
  • my issue with this is, I have the date already formatted to my liking, I want to add 5 days to the already formatted date. – user979331 Nov 19 '15 at 21:29
  • @user979331 It would be a good idea to make a function to accept a date and return a formatted string. Then you would be able to perform operations on the original date object and serialize it to string whenever you want. – 11thdimension Nov 19 '15 at 21:31
  • @user979331 Parse it back into a date and do what Billy suggests – Ruan Mendes Nov 19 '15 at 21:31