Bootstrap Datepicker Set Default Date Not Working

bootstrap datepicker today as default

This should work:

$("#datepicker").datepicker("setDate", new Date());

And for autoclose (fiddle):

$('#datepicker').datepicker({
"setDate": new Date(),
"autoclose": true
});

jQuery > datepicker API

Set default date for bootstrap datepicker

Use formate: instead of dateFormat:

<script type="text/javascript" >
function toggle_dp() {
$("#myModal").modal("show");
$("#datepicker").datepicker({
format: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
defaultDate: new Date(toMMDDYYYY(startDate))
});

}

function toMMDDYYYY(date) {
var datePart = date.split("/");
var MMDDYYYY = [datePart[1], datePart[0],datePart[2]].join('/');
return MMDDYYYY
}
</script>

Bootstrap Datetime picker dynamic default date not working

$('#current_session_date').datetimepicker({
defaultDate: defaultD,
});

This creates the datetimepicker with an initial value, so doesn't work if the datetimepicker already exists.

You either need to call date([newDate]) to update it in place (you'll need to initialise it elsewhere) or destroy() it when the modal is closed, allowing you to remake it with a new initial value.

Bootstrap Datepicker - Set default picker date, NOT display value

Here it is:

$('.datepicker').datepicker({
defaultViewDate: {year:2000, month:0, day:1},
});

And the js Fiddle:

https://jsfiddle.net/mb34zwg3/

Set Default Date Bootstrap Datepicker

You can do:

$('#dob').datepicker('setDate', new Date(2006, 11, 24));
$('#dob').datepicker('update');
$('#dob').val('');

Fiddle Demo

How to put a default date in bootstrap datetimepicker

Just set the value after setting up the datetimepicker:

$('.form_date').datetimepicker({
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 2,
forceParse: 0,
});
$('#dtp_input2').val(Date());


Related Topics



Leave a reply



Submit