set max date dynamicaly in jquery

383 views Asked by At

I am try to implementing datepicker using jquery ,I want set max date of second datepicker is to selected date of first datepicker.

here is my code :-

        $('#firstDatePiker').datetimepicker({
        dayOfWeekStart : 1,
        lang:'en',
        startDate:""+currentdate,
         minDate: 0
        });

        $('#proofingDate').datetimepicker({
        dayOfWeekStart : 1,
        lang:'en',
        startDate:""+currentdate,
         minDate: 0,
        }); 

I have call function onblur event on first datepiker as follows:-

function addmaxDate()
{    
  var proDatetemp=$('#runDate').val();
  var maxDate = new Date(proDatetemp );
  $( "#proofingDate" ).datetimepicker( "option", "maxDate", maxDate );    
}
1

There are 1 answers

1
Guruprasad J Rao On BEST ANSWER

You can use onShow method of datetimepicker

$('#firstDatePiker').datetimepicker({
    dayOfWeekStart: 1,
    lang: 'en',
    startDate: "" + currentdate,
    minDate: 0,
    onShow:function(ct){//current time
        this.setOptions({
            maxDate:$('#proofingDate').val()?$('#proofingDate').val():false
        })
    },
});

$('#proofingDate').datetimepicker({
    dayOfWeekStart: 1,
    lang: 'en',
    startDate: "" + currentdate,
    minDate: 0,
    onShow:function(ct){
         this.setOptions({
            maxDate:$('#firstDatePiker').val()?$('#firstDatePiker').val():false
         })
    },
});