ThomasK
ThomasK

Reputation: 2220

jquery datetime picker set start and end of day

I need to limit the range of available times to be between 12 and 23 (24 hour clock) with 10 minute steps.

12:00, 12:10, 12:20, 12:30 and so on all the way to 22:50.

allowTimes is one option. But one would need to write all those times into the code.

By using step: the list with times is correct. But it starts all the way down at 00:00.

$('#hyperbowling_datetime').datetimepicker({
    format:'d.m.Y H:i',
    lang:'no',
    startDate:'+1971/05/01',//or 1986/12/08
    hourMin: 12,
    hourMax: 23,
    step:10,
    /*
    allowTimes:[
        '12:00', '13:30', '15:00', '16:30', 
        '17:00', '18:00', '18:30',
    ]
    */
});

Is there a quick solution to this?

Upvotes: 0

Views: 189

Answers (1)

m.hassaballah
m.hassaballah

Reputation: 250

You can pass "immediately invoked function" to allowTimes option and then generate the hours array using for loop like the below one :

 allowTimes: function getHours() {
        var hours = [];
          for(var i=12; i <= 24; i++) {
            hours.push( i + ":00");
        }
    return hours;
    }()

Upvotes: 1

Related Questions