MinDate not working in bootstrap datepicker

I use 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 select a date from today to the future (not past date). Datepicker is displayed, and this allows me to select the last date as well. What's wrong?

+7
source share
9 answers

Try using this method:

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

There is no need to use Date var to use the startDate parameter.

+21
source

try using startDate as follows:

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

I hope this helps you

+6
source

Since none of the answers worked for me. I managed to disable older dates using the onRender option

 $('.datepicker').datepicker({ onRender: function(date) { return date.valueOf() < new Date().valueOf() ? 'disabled' : ''; } }); 
+6
source

My code is: Bootstrap Datetimepicker (mindate). My code works in all browsers like ff, chrome etc. Please see the example below. I work for me.

  $('#datetimepicker1').datetimepicker({ //minDate: new Date() + 1, minDate:moment(), Default: true, defaultDate: new Date(), pickTime: false, use24hours: false, format: 'MM-DD', icons: { time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-arrow-up", down: "fa fa-arrow-down" }, // minDate: moment(+1), }); 
+3
source

try

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

Back date

 var last7Days = new Date(); last7Days.setDate(last7Days.getDate()-7); $(function () { $( "#datepicker1" ).datepicker({ format: 'yyyy-mm-dd', autoclose: true, startDate: last7Days }); }); 
+1
source

The following should work: minDate: new Date ()

0
source

you can use the following working code that disables all past dates -

for DatePicker working script

 $(function () { //get Today Date var currDate = new Date(); $('#datetimepicker').datepicker({ startDate : currDate }); }); 

and for DateTimePicker this will work ( Fiddle ) -

 $(function () { $('#datetimepicker').datetimepicker({ minDate : moment() }); }); 
0
source

I spent some time looking at the documentation looking for this option. The DatePicker loader comes with a startDate parameter that accepts dates or strings from the documentation:

The date must be in the local time zone. The string must be collapsible with format

There is an online demo that allows you to try different options. If you enter now (or new Date() ) in the startDate field, the date picker will not let you select a date before the current date.

The output of a small code on the side will show you the code that you should use on your website, in this case it will be:

 $('#sandbox-container input').datepicker({ startDate: "now" }); 

You need to switch the #sandbox-container input for a selector that points to your datepicker element.

0
source

try using startDate :

 startDate: "dateToday" 
-3
source

Source: https://habr.com/ru/post/955390/


All Articles