Skip to content Skip to sidebar Skip to footer

Setting Max Time In Jquery Timepicker

Below is the Current JQuery for My Time Pickers. If time is picked from #from field it set max time of #to to selected time. If I picked 1am from #from the max time that can be pic

Solution 1:

Surround the var with Number to make jQuery recognize it as number to add 4 to it

$('#from').on('changeTime', function() {
  var sFrom=$(this).val();
  var sFromPuls=Number(sFrom)+4; // Surround with Number()
  $('#to').timepicker({ 'minTime': '9',
  'maxTime':sFromPuls, //write correct var name 'scrollDefaultNow': true,
  'step': 60 });
});

Solution 2:

You can refer to onSelect documentation and use it on your timepicker

$('#example').datetimepicker({
    onSelect: function(){
              //Here you can add 4 hours to the start time
        }
});

Solution 3:

My Problem was solved by following code -

$('#from').timepicker({ 'minTime': 8,'maxTime': 20,'scrollDefaultNow': true,'step': 60 });
    $('#from').on('change', function() {
        var fromTime=$(this).val();
        var hrs = Number(fromTime.match(/^(\d+)/)[1]);
        var format = fromTime.match(/00(.*)$/)[1];
        if (format == "pm" && hrs < 12) hrs = hrs + 12;
        if (format == "am" && hrs == 12) hrs = hrs - 12;
        var hours = (hrs+4).toString();         
        var sFromPuls= (parseInt(osSeletecdTime)+4).toString();
        $('#to').timepicker({ 'minTime': fromTime,'maxTime':hours ,'scrollDefaultNow': true,'step': 60 });
    });

Post a Comment for "Setting Max Time In Jquery Timepicker"