There is a calendar configured through

$('.calendar').datetimepicker({ theme: 'dark', minDate: new Date('<?=time()?>'), onSelectTime: onSelectTime }); 

The date works correctly, that is - the date that has already been, can not be selected. But with time, the problem is, the time that was already possible to choose, and so it is not necessary. And in general the problem is that time goes without minutes, but only round the clock.

 00:00 - 23:00 

Tried to change the format parameter to: H: i and others, does not work. It is necessary in general that, just as the date should follow, in the same order, without choosing the past tense. Save

    2 answers 2

    The @Alex question remains, how to remove / replace the time if it is less than the current one, in the example, choose tomorrow, then the time is less than the current one, then select the current date, the result cannot be selected, but in the input from the last choice ... it looks like a flaw in the plugin , or change minTime to add to another place

     $(function() { $(".calendar").datetimepicker({ minTime: new Date, format: "dmY H:m", minDate: new Date, onSelectDate: function(ct, $i) { this.setOptions({ minTime: ct.getTime() > new Date ? false : 0 }) } }) }); 
     <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/jquery.datetimepicker.min.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.js"></script> <input type="text" class="calendar" /> 

    • and what is stopping you in onSelectDate when choosing the current date is to immediately write the current date and the current time directly into the input - Alex
    • @Alex could you show the code - roni
    • added an example to his answer - Alex
    • I did just that, and I also took the date from the server, so it was necessary that if it was already 23 and not yet 00:00, so that 23 could still be chosen, and so with everyone, the condition> =. All the rules, the problem is solved. Thank! - And

    By the minimum date I used their design:

     minDate: 0, //today 

    by time - you can set the allowed time (if programmatically, you can specify any interval)

     {allowTimes:[ '09:00', '11:00', '12:00', '15:30', '21:00' ]} 

    Then you can screw the setting of the minimum time depending on the selected date for the event.

      onSelectDate:function(ct,$i){ minTimesNew = .... $('.calendar').datetimepicker('setOptions', {minTime:minTimesNew }); } 

    check here, if today, then set the minimum time value - current ({minTime: 0} // now), otherwise all {minTime: '00: 00 '}

    Example. When you select the current date, the next hour is set by default:

     $(function() { $(".calendar").datetimepicker({ minTime: 0, format:'Ymd H:i', minDate:'-1970/01/01', // today is minimum date onSelectDate: function(ct, $i) { var minTime, now = new Date; if(ct.getTime() > now){ minTime = false; }else{ var d = $i.val().substr(0, 11) + (Number(now.getHours()) + 1).toString() + ':00'; $i.val(d); minTime = 0; } this.setOptions({ minTime: minTime }) } }) });