Bootstrap datepicker disabling past dates without current date

前端 未结 20 2171
[愿得一人]
[愿得一人] 2020-11-27 04:55

I wanted to disable all past date before current date, not with current date. I am trying by bootstrap datepicker library \"bootstrap-datepicker\" and using following code:<

20条回答
  •  醉梦人生
    2020-11-27 05:39

    It depends on what format you put on the datepicker So first we gave it the format.

        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!
    
        var yyyy = today.getFullYear();
        if(dd<10){
            dd='0'+dd;
        } 
        if(mm<10){
            mm='0'+mm;
        } 
        var today = yyyy+'-'+mm+'-'+dd; //Here you put the format you want
    

    Then Pass the datepicker (depends on the version you using, could be startDate or minDate which is my case )

        //Datetimepicker
        $(function () {
            $('#datetimepicker1').datetimepicker({
                minDate: today, //pass today's date
                daysOfWeekDisabled: [0],
                locale: 'es',
                inline: true,
                format: 'YYYY-MM-DD HH:mm', //format of my datetime (to save on mysqlphpadmin)
                sideBySide: true
            });
        });
    

提交回复
热议问题