I am selecting a date in the Air Datepicker and trying to compare today's date to the selected date to determine the difference in days. So, for example, if today is 12/11/2016 and I select 12/20/2016, I want to get the difference, which is 9.
I keep running into the following error: "end.diff is not a function".
I've stripped the following code down to the essentials:
HTML
<form> <input id="datereq" name="datereq" type="text" class="dateReq" value="" /> </form> <div id="selected"></div>
JQUERY
var date = new Date(), disabledDays = [0, 6]; $('.dateReq').datepicker({ dateFormat: 'mm/dd/yyyy', minDate: new Date(), language: 'en', autoClose: true, onRenderCell: function(date, cellType) { if (cellType == 'day') { var day = date.getDay(), isDisabled = disabledDays.indexOf(day) != -1; return { disabled: isDisabled }; } }, // Display Appropriate Order Type Options onSelect: function onSelect(fd, date) { var now = moment(new Date()).format('MM/DD/YYYY'), end = fd, days = end.diff(now, 'days'); $('#selected').html('now:' + now + 'end:' + end + 'diff:' + days); //console.log('end:' + end); //console.log('diff:' + days); } });
Fiddle