How to set a default date in Bootstrap Datepicker?
I want to set a date : 24/12/2006
When I open datepicker it should show me this date select on calender.
Code:
$(function()
{
$('#dob').datepicker(
{
<!--viewMode: "years",-->
onRender: function(date)
{
//return date.valueOf() > now.valueOf() ? 'disabled' : '';
}
}
);
});
Here is a fiddle:
http://jsfiddle.net/ymp5D/204/
Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.
To set current date in control to which jQuery UI datepicker bind, use setDate() method. Pass date object which needs to be set as an argument to setDate() method. If you want to set it to current date then you can pass 'today' as argument.
The jQuery DatePicker plugin supports multiple Date formats and in order to set the dd/MM/yyyy Date format, the dateFormat property needs to be set. The following HTML Markup consists of a TextBox which has been made Read Only.
You can do:
$('#dob').datepicker('setDate', new Date(2006, 11, 24));
$('#dob').datepicker('update');
$('#dob').val('');
Fiddle Demo
Above accepted solution is staled, To help others who has the newest files, if you have Version 4 or newer, and you want to call a method, here is an example for bootstrap datetimepicker method :
$('#eventDate').data("DateTimePicker").date(moment(date).format('YYYY-MM-DD'));
bootstrap.datetimepicker format Option sample :
$('#eventDate').datetimepicker({ format: 'YYYY-MM-DD' });
for more see here (but without valid sample :) ): http://eonasdan.github.io/bootstrap-datetimepicker/Options/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With