Bootstrap-datepicker: startDate option disabling past dates with current date

Created on 20 Apr 2013  Â·  12Comments  Â·  Source: uxsolutions/bootstrap-datepicker

I wanted to disable all past date before current date and using following code:

$('#date').datepicker({
startDate: new Date()
});

It works fine. But it is disabling date till today. As example if today is 04-20-2013 and i disable past dates by setting startDate: new Date(). but I can select date from 04-21-2013

Most helpful comment

you can set a temporary variable before initializing datepicker:

var nowDate = new Date();
var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);

and use this as option:

$('#date').datepicker({ 
startDate: today 
});

now you can also select the current day!

All 12 comments

you can set a temporary variable before initializing datepicker:

var nowDate = new Date();
var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);

and use this as option:

$('#date').datepicker({ 
startDate: today 
});

now you can also select the current day!

Nice!!!! This one helped.

Need to add that to doc so I will be aware of it.

Thank you

Thank you.

You can either use HTML data attributes like data-date-startdate=’yyyy-mm-dd’ or the startDate attribute while initializing the datepicker. You can know more about disabling past dates in bootstrap datepicker here http://codezag.com/disabling-past-dates-bootsrap-datepicker/

Narendran Parivallal It's not working properly

Related issues

mrlife picture mrlife  Â·  4Comments

alexandrubau picture alexandrubau  Â·  3Comments

kzpromo picture kzpromo  Â·  5Comments

italoborges picture italoborges  Â·  4Comments

PlippiePlop picture PlippiePlop  Â·  6Comments