0

Hi I have this format bootstrap datepicker

$('#dte').datepicker({
    format: 'dd/mm/yyyy'
});

and I want to add example 5days

var d1 = new Date($('#dte').val());
var end  = d1 + $('#numberToAdd').val();

But I get invalid date results.

Can someone help me please what is the correct way to add dates in javascript

Thank you in advance.

Ignacio Ara
  • 2,476
  • 2
  • 26
  • 37
jemz
  • 4,987
  • 18
  • 62
  • 102
  • Possible duplicate of [Compare two dates with JavaScript](https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript) – Metalik Jun 14 '18 at 16:02
  • Possible duplicate of [Converting string to date in js](https://stackoverflow.com/questions/5619202/converting-string-to-date-in-js) – 001 Jun 14 '18 at 16:03
  • 1
    Neither of these are duplicates you guys -- please read the question. He wants to add a certain number of days to a date something, not compare them or convert it to a string. – Thomas Cohn Jun 14 '18 at 16:04
  • Possible duplicate of [How to add 30 minutes to a JavaScript Date object?](https://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object) – Thomas Cohn Jun 14 '18 at 16:05
  • @Helium_1s2 Well, the OP will need to convert the value of the text field to a date to get `d1`, so they'll need Johnny's dupe. – Heretic Monkey Jun 14 '18 at 16:25
  • OP already converts to a date object correctly with `var d1 = new Date($('#dte').val());`. – Thomas Cohn Jun 14 '18 at 16:48
  • And OP's question is very specifically "what is the correct way to add dates in javascript". So even if he were parsing the string incorrectly, it would not be appropriate to flag it as a duplicate of a post about converting a string to a date. – Thomas Cohn Jun 14 '18 at 16:49

0 Answers0