How to add a week to a date and display it in a format?

  • 0
    There is a date in this format "2020-11-30". You need to add a week to it and print "yyyy-mm-dd" in the same format.
    JavaScript Hunter Logan, Sep 22, 2020

  • 4 Answers
  • 0
    new Date(Date.parse('2020-11-30') + 7 * 24 * 60 * 60 * 1000)


    UPD,

    Or like this:

    const d = new Date('2020-11-30')
    d.setDate(d.getDate() + 7)
    Anonymous

  • 0
    Look at momentjs there are a bunch of date helpers
    Anonymous

  • 0
    the easiest way is to connect dayjs



    Anonymous

  • 0
    var yourdate = new Date("2020-02-29");
    yourdate.setDate(yourdate.getDate() + 3);
    var curr_date = yourdate.getDate();
    var curr_month = yourdate.getMonth() + 1;
    var curr_year = yourdate.getFullYear();
    alert(curr_year + "-" + curr_month + "-" + curr_date);
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!