1

I have this script;

showDiff();
function showDiff() {
    var date1 = new Date("2016/03/14 00:00:00");
    var date2 = new Date();
    var diff = (date2 - date1);
    var diff = Math.abs(diff);
    var result;
    if (diff > 432000000) {
        result = 100 + "%";
    } else {
        result = (diff/4320000) + "%";
    }
    document.getElementById("showp").innerHTML = result;
    document.getElementById("pb").style.width = result;

    setTimeout(showDiff,1000);
}

Now I want to get exactly one week added to date1 when atleast one week has passed since that time. That date has to be saved so that one week later, another week can be added to date1. So basically every monday there has to be one week added to date1. How do I this?

GreenGiant
  • 4,930
  • 1
  • 46
  • 76

1 Answers1

1

The Date object has both a getDate() and setDate() function (date referring to the day of the month, no the full calendar date), so it's really as simple as getting a Date object and setting its date to +7 days from itself.

Example:

var weekFromNow = new Date();
weekFromNow = weekFromNow.setDate(weekFromNow.getDate()+7);

Just to clarify, the Date object contains a full calendar date and time, with its date property referring just to the day in the month (also different from its day property, which is the day of the week).

Harris
  • 1,775
  • 16
  • 19