Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minDate not working in bootstrap datepicker

I am using this bootstrap datepicker http://www.eyecon.ro/bootstrap-datepicker/:

<script type="text/javascript">
var dateToday = new Date();
$(function() {
    $("#id_deadline").datepicker({minDate: dateToday});
});
</script>

I want to let select the date from today to future only (not a past date). Datepicker is showing up and it is letting me select the past date too. What's wrong?

like image 280
pynovice Avatar asked Oct 07 '13 08:10

pynovice


People also ask

Why bootstrap datepicker is not working?

Because you're defining the code in the head the body and its contents haven't been loaded yet; so the selector finds no elements to initialize datepicker. If you don't want to use document. ready functionality you could also move the script to the end of the body tag.

How to initialize Bootstrap datepicker?

For most datepickers, simply set data-provide="datepicker" on the element you want to initialize, and it will be intialized lazily, in true bootstrap fashion. For inline datepickers, use data-provide="datepicker-inline" ; these will be immediately initialized on page load, and cannot be lazily loaded.

How to disable current date in Bootstrap datepicker?

ready(function () { $('#date'). datetimepicker({ //defaultDate: new Date() //date-disabled="now" //default: false }); }); bootstrap-datetimepicker.


2 Answers

try using startDate with this way :

$("#id_deadline").datepicker({startDate: new Date()});

I hope it will help you

like image 103
Mohamed Avatar answered Sep 28 '22 12:09

Mohamed


try,

var dateToday = new Date(); 
$(function () {
    $( "#datepicker1" ).datepicker({
        format: 'yyyy-mm-dd',
      autoclose: true,
      startDate: dateToday
    });
});

Backdate

var last7Days = new Date(); 
last7Days.setDate(last7Days.getDate()-7);
$(function () {
    $( "#datepicker1" ).datepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        startDate: last7Days
    });
});
like image 25
Waruna Manjula Avatar answered Sep 28 '22 14:09

Waruna Manjula