Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add maxdate in bootstrap datepicker

I need to add maxdate for datepicker and i am using this plugin

cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.min.js

and this is my datepicker code:

.datepicker({
    autoclose: true,
    todayHighlight: true,
    format: 'mm/dd/yyyy',
    minDate:  new Date(),                                            
    maxDate: +42,
    startDate: indianTimeZoneVal
})

But maxdate is not working i need current date to next 42 days

like image 873
kumar swamy Avatar asked Aug 21 '17 13:08

kumar swamy


2 Answers

Not sure bootstrap-datepicker has minDate and maxDate.

But for sure it has startDate and endDate instead. Try this,

.datepicker({
 autoclose: true,
 todayHighlight: true,
 format: 'mm/dd/yyyy',
 startDate: new Date(),
 endDate: new Date(new Date().setDate(new Date().getDate() + 5))
})

Here is the example fiddler for your reference.

Hope it helps.

like image 53
RaJesh RiJo Avatar answered Oct 06 '22 00:10

RaJesh RiJo


$('#element').datepicker({
autoclose: true,
todayHighlight: true,
format: 'mm/dd/yyyy',
startDate:  new Date(),                                            
endDate: new Date(new Date().setDate(new Date().getDate() + 42)),
minDate:  new Date(),                                            
maxDate: new Date(new Date().setDate(new Date().getDate() + 42))
})
like image 22
Fatehi_Alqadasi Avatar answered Oct 05 '22 23:10

Fatehi_Alqadasi