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:<
use
startDate: '-0d'
Like
$("#datepicker").datepicker({
startDate: '-0d',
changeMonth: true
});
Please refer to the fiddle http://jsfiddle.net/Ritwika/gsvh83ry/
**With three fields having date greater than the **
<input type="text" type="text" class="form-control datepickstart" />
<input type="text" type="text" class="form-control datepickend" />
<input type="text" type="text" class="form-control datepickthird" />
var date = new Date();
date.setDate(date.getDate()-1);
$('.datepickstart').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd/mm/yyyy',
startDate: date
});
$('.datepickstart').datepicker().on('changeDate', function() {
var temp = $(this).datepicker('getDate');
var d = new Date(temp);
d.setDate(d.getDate() + 1);
$('.datepickend').datepicker({
autoclose: true,
format: 'dd/mm/yyyy',
startDate: d
}).on('changeDate', function() {
var temp1 = $(this).datepicker('getDate');
var d1 = new Date(temp1);
d1.setDate(d1.getDate() + 1);
$('.datepickthird').datepicker({
autoclose: true,
format: 'dd/mm/yyyy',
startDate: d1
});
});
});
If your requirement is to disable the startDate and endDate dynamically based on one on another you can you this.
$('#date2').datepicker({
todayHighlight: true,
autoclose: true,
format: "dd/mm/yyyy",
clearBtn : true
}).on('show', function(e){
var date = $('#date3').datepicker('getDate');
if(date){
$('#date2').datepicker('setEndDate', date);
}
});
$('#date3').datepicker({
todayHighlight: true,
autoclose: true,
format: "dd/mm/yyyy",
clearBtn : true
}).on('show', function(e){
var date = $('#date2').datepicker('getDate');
if(date){
$('#date3').datepicker('setStartDate', date);
}
});
If your requirement is just disabled past dates then you can use below snippet.
$('#date2').datepicker({
todayHighlight: true,
autoclose: true,
format: "dd/mm/yyyy",
clearBtn : true,
startDate : new Date()
})
If your requirement is just disabled future dates then you can use below snippet.
$('#date2').datepicker({
todayHighlight: true,
autoclose: true,
format: "dd/mm/yyyy",
clearBtn : true,
endDate : new Date()
})
I hope it will help someone.
var nowDate = new Date();
var today = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 0, 0, 0, 0);
$('#date').datetimepicker({
startDate: today
});
Use minDate
var date = new Date();
var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
$('#date').datepicker({
minDate: today
});
The solution is much simpler:
$('#date').datepicker({
startDate: "now()"
});
Try Online Demo and fill input Start date: now()