Hello. It is necessary on JavaScript (jquery) to determine what date will be after a certain number of days, the date should be of the form dd-mm-yyyy

On php, you can do it like this: date("dmY", strtotime('15 days'));

It is necessary on JavaScript (jquery). I would be grateful for the help.

  • objNewDate.SetDate(objOldDate.GetDate + varDaysToAdd) - Akina
  • @Akina and how to display today's date in dd-mm-yyyy format? -
  • var datNow = new Date(); strNow = datNow.format("dd-mm-yyy"); - Akina

3 answers 3

There is a good Moment.js library. It has a function add

    Code in two lines without connecting additional libraries.

     var dateNow = new Date(); dateNow.setDate(dateNow.getDate() + days); 

    However, even if the date is more than the actual number of days in the month, the month is automatically incremented.

    • I wonder how to make the exit date be 01-01-2018 (day-month-year)? it would be great - iKey

     function get(data, day) { data = data.split('-'); data = new Date(data[2], +data[1] - 1, +data[0] + day, 0, 0, 0, 0); data = [data.getDate(), data.getMonth() + 1, data.getFullYear()]; data = data.join('-').replace(/(^|\/)(\d)(?=\/)/g, "$10$2"); return data } console.log(get("24-12-2018", 2));