Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap datepicker today as default

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" automatically, so I did an inefficient way

HTML:

<input type="text" value ="today();" id="datepicker"/> 

JS:

 $('#datepicker').datepicker(); function today(){     var d = new Date();     var curr_date = d.getDate();     var curr_month = d.getMonth() + 1;     var curr_year = d.getFullYear();     document.write(curr_date + "-" + curr_month + "-" + curr_year); } 

Online Sample: http://jsfiddle.net/BXZk2/

Just looking for an easy solution to make the default day as "TODAY".

Thanks

like image 903
olo Avatar asked Mar 15 '13 01:03

olo


People also ask

How do I change the default date in datepicker to today?

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 can I get current date in datepicker?

Set Current Date in DatePicker using jQueryvar now = new Date(); var day = ("0" + now. getDate()).


1 Answers

This should work:

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

And for autoclose (fiddle):

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

jQuery > datepicker API

like image 125
Nic Avatar answered Sep 28 '22 19:09

Nic