Set today's date as default date in jQuery UI datepicker

Chris Abrams picture Chris Abrams · Feb 6, 2011 · Viewed 319.4k times · Source

I just want today's date to be the default value in the input that is using jQuery UI's datepicker:

<input id="mydate" type="text" />

I tried the below code but it didn't work:

var currentDate = new Date();  
$("#mydate").datepicker("setDate",currentDate);

Answer

Martin Eden picture Martin Eden · Jul 5, 2013

You need to make the call to setDate separately from the initialization call. So to create the datepicker and set the date in one go:

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

Why it is like this I do not know. If anyone did, that would be interesting information.