Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Default Date Bootstrap Datepicker

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/

like image 643
Hassan Sardar Avatar asked Feb 19 '14 13:02

Hassan Sardar


People also ask

How do I change the default date format in bootstrap DatePicker?

Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.

How do I set DatePicker to current date?

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.

How do I change DatePicker format from DD MM to YYYY?

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.


2 Answers

You can do:

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

Fiddle Demo

like image 117
Felix Avatar answered Sep 21 '22 18:09

Felix


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/

like image 38
Bashar Abu Shamaa Avatar answered Sep 18 '22 18:09

Bashar Abu Shamaa