troubleshooting Question

Bootstrap/javascript/jquery - Further manipulating StartDates and EndDates with datepicker

Avatar of Member_2_1242703
Member_2_1242703 asked on
BootstrapjQueryJavaScript.NET MVCWeb Development
10 Comments1 Solution282 ViewsLast Modified:
I'm currently using this script to stop the end date at the next sunday on a datepicker control (following the start date.)
I want to amend it so that if the StartDate selected is a Sunday, only that day can be selected.

i.e. March 26th, 2017 is selected as the start date.
The only available date to be selected for EndDate would be March 26th, 2017.

var dateFormat = "mm/dd/yy";
$(document).ready(function(){
  var from = $(".start").datepicker({
    changeMonth: true,
   dateFormat: dateFormat,
    numberOfMonths: 1,
    onSelect: function(dt, inst){
      var fromDt = $(this).datepicker("getDate");
      var nextSunday = new Date(fromDt.getTime());
      nextSunday.setDate(nextSunday.getDate() + 7 - fromDt.getDay());

      to.datepicker("option", "minDate", dt);
      to.datepicker("option", "maxDate", nextSunday);
      loadHours();
    }
  });

  var to = $(".end").datepicker({
    changeMonth: true,
    dateFormat: dateFormat,
    numberOfMonths: 1,
    onSelect: function(dt, inst){
        from.datepicker("option", "maxDate", dt);
        loadHours();
    }
  });
});
ASKER CERTIFIED SOLUTION
Pravin Asar
Principal Systems Engineer
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros