Reputation: 13
I am trying to add 3 days to the date I get from the jQuery Datepicker as a variable as I show in this example:
var dateSelected = fromDateInput.datepicker('getDate');
var count = 3;
var lol = dateSelected.setDate(dateSelected.getDate() + count);
console.log(lol);
If I use the variable I will get this in the console for example: 1449615600000.
If I do it like this:
var dateSelected = fromDateInput.datepicker('getDate');
var count = 3;
dateSelected.setDate(dateSelected.getDate() + count);
console.log(dateSelected);
I will get the correct date (The date I select in the datepicker + 3 days)
Why can't I use it in a variable?
Upvotes: 1
Views: 1409
Reputation: 401
The result of setDate is the number of milliseconds since midnight 1st January 1970. In your second example you are using the actual date object, which is why the second example gives you what you want and the first does not.
Upvotes: 0
Reputation: 86
Try This:
var d = new Date("mm/dd/yyyy");
d.setDate(d.getDate()+3);
Upvotes: 0
Reputation: 5822
Try this:
var dateSelected = fromDateInput.datepicker('getDate');
var count = 3;
var dateUpdated = dateSelected.getDate() + count;
dateSelected.setDate(dateUpdated);
console.log(dateUpdated);
The setDate
method doesn't return anything. See the documentation: jQuery UI DatePicker setDate
Upvotes: 1