Problem with Javascript Datepicker for Dates > Day 12

Asked

Viewed 31 times

1

Good morning,

I am having some problems in selecting dates higher than the 12th of a given month with the following script:

<script type="text/javascript">
        $(function () {
            var date = new Date();
            var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
            $('#datepickerInicio').datepicker({
                defaultDate: today,
                dateFormat: 'dd/mm/yy',
                orientation: 'bottom',
                dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
                dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S', 'D'],
                dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom'],
                monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
                monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
                nextText: 'Próximo',
                prevText: 'Anterior',
                locale: 'PT-pt',
                maxDate: today
            });

            $('#datepickerInicio').datepicker('setDate', today);

            console.log($('#datepickerInicio').data());
            console.log($('#datepickerInicio').val());
        });

        $('#btnSeach').click(function () {
            console.log($('#datepickerInicio').val());
        })
    </script>

Since I saw a console:

defaultDate: Wed Jul 17 2019 00:00:00 GMT+0100

datepicker: append: k.fn.init [] currentDay: 17 currentMonth: 6 currentYear: 2019

That is, supposedly the date should be 17/07/2019. However if I put dates 12/07/2019 or lower works perfectly.

From what I understand it has to do with the Mes starting from 0 to 11, however I have no idea how I can resolve this situation, because the datetimepicker does not accept dates above 12 whichever month is selected...

Does anyone know how I can solve this problem? Is that supposedly the datetimepicker is taking the "day" as "month".

Regards

1 answer

1

Friend, do a test before I run your code, delete this line from the dataPicker statement.

maxDate: today
  • Removing this line has exactly the same problem!

Browser other questions tagged

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