Search code examples
jqueryjquery-uidatetimepicker

How to Restrict date in jquery datetimepicker based on another datetimepicker


I have two datetimePickers in the same page and I wanna change the second datetimepicker's minDate depending the first one. Here is my code:

  $(function() {
    if ($("#p-from").length > 0) {
        $('#p-from').datetimepicker();
    }

    if ($("#p-to").length > 0) {
        $('#p-to').datetimepicker();
    }

});

i am used

jquery.datetimepicker.full.min.js

Solution

  • Please check this: http://jsfiddle.net/tSrGx/28/

     $(function () {
         $("#from").datepicker({
    
             changeMonth: true,
             numberOfMonths: 1,
             minDate: -0,
             onClose: function (selectedDate) {
                 var date2 = $('#from').datepicker('getDate');
                 date2.setDate(date2.getDate() + 1);
                 $("#to").datepicker("option", "minDate", date2);
             }
         });
    
         $("#to").datepicker({
    
             changeMonth: true,
             numberOfMonths: 1
         });
     });