javascript date + 1 and -1


I have a text in the date format yyyy-mm-dd

For example if my value is 2015-08-20, i need to change it to +1 day and -1

results like this 2015-08-21 and 2015-08-19

any idea?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F IgorDeveloperCommented:
This is an example using getDate() and setDate() adding days.
joyacv2Author Commented:

I need the output format in the yyyy-mm-dd format
Julian HansenCommented:
How about this
Date.prototype.yyyymmdd = function(showtime) {
  var dateString = this.getFullYear() +"-"+
    ("0" + (this.getMonth()+1)).slice(-2) +"-"+
    ("0" + this.getDate()).slice(-2) + " ";
  if (showtime || false) {
    dateString += ("0" + this.getHours()).slice(-2) + ":" +
    ("0" + this.getMinutes()).slice(-2) + ":" +
    ("0" + this.getSeconds()).slice(-2) + "." +
    ("00" + this.getMilliseconds()).slice(-3)
  return dateString;
var d = new Date('2015-08-20');
var tomorrow = new Date(d);
tomorrow.setDate(d.getDate() + 1);
var yesterday = new Date(d);
yesterday.setDate(d.getDate() -1);

Open in new window

Working sample here
F IgorDeveloperCommented:
Use like this example:


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joyacv2Author Commented:
works perfect now!!!! thanks!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.