How to disable previous hours of the current with javascript datetimepicke

Asked

Viewed 65 times

0

I have a calendar that works correctly that eliminates weekends, but I also wanted for example: now it is 11 hours so all previous times were disabled so it is not possible to select.

$(document).ready(function(e) {

    $.datetimepicker.setLocale('pt-BR');


    $("#hora").datetimepicker({
        minDate: 0,
        dayOfWeekStart: 1,

        addSliderAccess: true,
        sliderAccessArgs: {
            touchonly: false
        },
        format: 'd/m/Y H:i',

        allowTimes: [
            '09:00', '09:30', '10:00',
            '10:30', '11:00', '11:30',
            '12:00', '12:30', '13:00', '13:30',
            '14:00', '14:30', '15:00', '15:30', '16:00', '16:30',
            '17:00', '17:30', '18:00'
        ],
        beforeShowDay: function(date) {
            var day = date.getDay();
            return [(day != 0 && day != 6)];


        }

inserir a descrição da imagem aqui

  • You can help https://stackoverflow.com/questions/43860602/datetimepicker-cannot-select-minutes-less-current-minute-although-hour-is

  • thanks David for the help ,but I found a solution

  • could you put the solution you found in answer to that question? So if other users have a similar problem they were able to solve the problem.

  • yes of course already this below

1 answer

1

I found a solution I will leave it here in which and only add a method minDateTime: 0

<script>
$(document).ready(function(e) {

    $.datetimepicker.setLocale('pt-BR');


    $("#hora").datetimepicker({
        minDate: 0,
        minDateTime: 0,

        format: 'd/m/Y H:i',

        allowTimes: [
            '09:00', '09:30', '10:00',
            '10:30', '11:00', '11:30',
            '12:00', '12:30', '13:00', '13:30',
            '14:00', '14:30', '15:00', '15:30', '16:00', '16:30',
            '17:00', '17:30', '18:00'
        ],
        beforeShowDay: function(date) {
            var day = date.getDay();
            return [(day != 0 && day != 6)];


        }


    });

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.