0

In my Laravel-5.8 application, I am using jQuery-1.12.4 for my datepicker

I have Leave Commencement Date and Leave Resumption Date

          <div class="col-sm-4">
            <div class="form-group">
                <label>Commencement Date:<span style="color:red;">*</span></label>
                <input type="text" id="commencement_date" class="form-control" placeholder="dd/mm/yyyy" name="commencement_date" value="{{old('commencement_date')}}" >
            </div>
          </div>                                         

          <div class="col-sm-4">
            <div class="form-group">
                <label>Resumption Date:<span style="color:red;">*</span></label>
                <input type="text" id="resumption_date" class="form-control" placeholder="dd/mm/yyyy" name="resumption_date" value="{{old('resumption_date')}}" >
            </div>
          </div>                                         

<script type="text/javascript">
    $(document).ready(function() {
        $(function () {
            $('#commencement_date').datepicker({
                dateFormat: 'dd-mm-yy',
              
            });
            $('#resumption_date').datepicker({
                dateFormat: 'dd-mm-yy',                
            });
        });
    });
</script>

How do I make:

  1. Minimum Date in Commencement Date to be current day and Max. Date to be Last Day of the year

  2. Minimum Date in Resumption Date to be current day + 1 (add a day to current day) and Max. Date to be Last Day of the year

Thanks

mikefolu
  • 1,203
  • 6
  • 24
  • 57
  • You'll get a better response if you show that you've made some effort, eg show us what you've tried, why you tried that, describe what happens, etc. We're here bcs we want to help, but SO isn't a code-writing service. Please visit the help centre and read [how to ask](https://stackoverflow.com/questions/how-to-ask), and how to create a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). – Don't Panic Jul 13 '20 at 23:33
  • There are *many* questions with answers here for both of the questions you ask, eg https://stackoverflow.com/questions/18130249/datepicker-limit-current-year, https://stackoverflow.com/questions/53128077/how-to-set-maxdate-is-last-day-of-december-on-current-year, https://stackoverflow.com/questions/20086584/datepicker-mindate-today-and-maxdate-31-dec-next-year, https://stackoverflow.com/questions/23785509/how-to-set-jquery-datetimepicker-mindate-is-tomorrow, https://stackoverflow.com/questions/20371800/datepicker-set-two-dates-with-startdate-tomorrow ... – Don't Panic Jul 13 '20 at 23:37

1 Answers1

0

You can use JS Date method, and add a day. Then attach within datePicker using minDate and MaxDate

var commencementDate = new Date();
var resumptionDate = new Date();

// add a day to the Resumption Date
resumptionDate.setDate(resumptionDate.getDate() + 1);

$('#commencement_date').datepicker({
      dateFormat: 'dd-mm-yy',
      minDate: commencementDate,
      maxDate: new Date(year, 11, 31)
          
});
$('#resumption_date').datepicker({
    dateFormat: 'dd-mm-yy', 
    minDate: resumptionDate ,
    maxDate: new Date(year, 11, 31)               
});
Watercayman
  • 7,970
  • 10
  • 31
  • 49