1
votes

Im using the datetimepicker here (https://xdsoft.net/jqplugins/datetimepicker/) I'm trying to a reservation, and I want that if the first datetime selected is the 20th of september at 12o'clock, i'd that in the second input I can only select of the previously selected day and above the previously selected hour

Can sombedy help please ? Thank's a lot in advance!

(the variable "nextDayReservation" is a date that's been been echo from the database, don't worry about it)

$("#datetimeFrom").datetimepicker({

            minDate:nextDayReservation, 
            maxDate: '+1970/02/01',
            format:'d/m/Y H:i', // d/m/Y H:i
            minTime: '09:00',
            maxTime: '22:00'

  });



$("#datetimeTo").datetimepicker({

            minDate:reservationDate,
            format:'d/m/Y H:i',
            maxDate: '+1970/02/01',
            minTime:'09:00',
            maxTime:'22:00'
  });
1

1 Answers

0
votes

Following works for date:

$("#datetimeFrom").datetimepicker({
  format: 'Y/m/d H:i',
  onShow: function(ct) {
    this.setOptions({
      maxDate: jQuery('#datetimeTo').val() ? jQuery('#datetimeTo').val() : false,
    })
  }
});

$("#datetimeTo").datetimepicker({
  format: 'Y/m/d H:i',
  onShow: function(ct) {
    this.setOptions({
      minDate: jQuery('#datetimeFrom').val() ? jQuery('#datetimeFrom').val() : false,
    })
  }
});
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.js"></script>

<input id="datetimeFrom" type="text">
<input id="datetimeTo" type="text">