I am using this bootstrap-datepicker for my datepicker. I\'d like the datepicker to choose \"today\" for start day or default day. I cannot figure out how to set \"today\"
According to this link Set default date of jquery datepicker, the other solution is
var d = new Date();
var currDate = d.getDate();
var currMonth = d.getMonth();
var currYear = d.getFullYear();
var dateStr = currDate + "-" + currMonth + "-" + currYear;
$("#datepicker").datepicker(({dateFormat: "dd-mm-yy" autoclose: true, defaultDate: dateStr });
I used this a little example and it worked.
$('#date').datetimepicker({
defaultDate: new Date()
});
demo : http://jsfiddle.net/m2fjw57b/1/
Set after Init
$('#dp-ex-3').datepicker({ autoclose: true, language: 'es' });
$('#dp-ex-3').datepicker('update', new Date());
This example is working.
For bootstrap date picker
$( ".classNmae" ).datepicker( "setDate", new Date());
* new Date is jquery default function in which you can pass custom date & if it not set, it will take current date by default
I changed code in line 1796 file 'bootstrap-datetimepicker.js'. It's worked for me
$(document).ready(function() {
var date = new Date();
var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
$('#datepicker1').datepicker({
format: 'dd-mm-yyyy',
orientation: 'bottom'
});
$('#datepicker1').datepicker('setDate', today);
});