0

The following javascript, processed via webpacker is setting the UI with the proper startDate (assuming today is 2020-12-19: 2018-12-19), but not the endDate, which is shown as 2020-12-19

(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[0],{

/***/ "./app/javascript/src/promotion_datespan.js":
/*!**************************************************!*\
  !*** ./app/javascript/src/promotion_datespan.js ***!
  \**************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function($) {$(function () {
  var startDate = new Date();
  startDate.setFullYear(startDate.getFullYear() - 2);
  $('#date_from').fdatepicker({
    initialDate: startDate,
    format: 'yyyy-mm-dd',
    disableDblClickSelection: true,
    leftArrow: '<<',
    rightArrow: '>>',
    closeIcon: 'X',
    closeButton: true
  });
});
$(function () {
  var endDate = new Date();
  endDate.getDate(endDate.getDate() - 2);
  $('#date_to').fdatepicker({
    initialDate: endDate,
    format: 'yyyy-mm-dd',
    disableDblClickSelection: true,
    leftArrow: '<<',
    rightArrow: '>>',
    closeIcon: 'X',
    closeButton: true
  });
});
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! jquery/src/jquery */ "./node_modules/jquery/src/jquery.js")))

/***/ })

}]);
//# sourceMappingURL=0-0fcba24322adb18c7ad0.chunk.js.map

why is getDatereturning the wrong data?

1 Answer 1

1

You made a typo, use endDate.setDate in stead off endDate.getDate.

I assume you want the endDate to be 2 days earlier then the current date.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.