0

Am trying to add days to a date that is picked by the user. How do I properly convert datetime string into JavaScript datetime that can be manipulated using .addDays?

  <input id="orderDate" type="date"> <input id="calculate" type="submit">
  <span id="test">abc</span><script src="https:/cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js">// <![CDATA[

document.getElementById('calculate').onclick = function() {
var adate = new Date(document.getElementById("orderDate").value).addDays(2);   
var arrivalDate = adate.addDays(3);
document.getElementById('test').innerHTML = arrivalDate;


}
  • Perhaps, worth looking into something like moment.js library or something like this: https://stackoverflow.com/questions/44827066/add-30-days-to-a-current-date-js – Nishant Dec 12 '20 at 13:32
  • That highly depends on the value of `#orderDate`. Also, `Date#addDays` does not exist. – str Dec 12 '20 at 13:33
  • You should also read about [*input type="date"*](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date), noting that dates in the format YYYY-MM-DD are parsed as UTC, not local. – RobG Dec 12 '20 at 14:05

0 Answers0