javascript date + 1 and -1

Hi,

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?
LVL 1
joyacv2Asked:
Who is Participating?
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.


https://jsfiddle.net/FranIg/wnp9bf5z/
0
joyacv2Author Commented:
Hi,

I need the output format in the yyyy-mm-dd format
0
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
0
F IgorDeveloperCommented:
Use like this example:

https://jsfiddle.net/FranIg/wnp9bf5z/5/

date2.toISOString().substring(0,10);

Open in new window

0

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!!!!
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.