momentjsdaterangepicker

How can I Set Week which starts from Friday and Ends on Next Thursday in DaterangePicker


I am Using JQuery DateRangePicker by Dan Grossman, right now I Configured it to enable Current Week's Dates only by momentjs.

Here is my script

var startDate = moment().startOf('week').toDate();
var endDate = moment().endOf('week').toDate();

$(document).ready(function () {
    $("#paymentDateTimePicker").daterangepicker({
       singleDatePicker: true,
       autoUpdateInput: false,
       minDate: startDate,
       maxDate: endDate,
       locale: {
          format: 'MM/DD/YYYY',
          firstDay: 1
       }
     });
});

By default, this configuration starts from Sunday to Saturday. Here is the output.

enter image description here

Now I want to Configure this dateRangePicker to starts on Friday instead of Sunday and ends on Thursday.

OR We can say From 2nd Of OCT to 8th of OCT.

I tried the add() and subtract() Methods of momentjs but can not find a proper solution to this.

Help me with this.


Solution

  • Thanks for your help, Above solution will work on regular days but if Today's Saturday then it will not work.

    here is a possible solution.

    var day = moment().day();
            var startDate;
            var endDate;
            if (day >= 5) {
                startDate = moment().day(5).toDate();
                endDate = moment().day(5).add(6, 'days').toDate()
            }
            else {
                 startDate = moment().startOf('week').subtract(2, 'days').toDate();
                 endDate = moment().endOf('week').subtract(2, 'days').toDate();
            }
    

    or can also use Datejs for easy chaining.