var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var d = year + "-" + month + "-" + day;
$('.date-pick').datepicker({ dateFormat: 'yy-mm-dd' }).val(d);
Thursday, July 29, 2010
jquery datepicker with current date and custom date format
I searched the net to find a more simpler solution to set the current date with jQuery UI datepicker but didn't find anything. So here is the solution I used. Mixture of both normal JavaScript and jQuery. You can also check out how to use a custom date format with jQuery UI datepicker.
Subscribe to:
Post Comments (Atom)
Great! Except when I choose a date from the calendar, the field is displayed with an extra yyyy on the end. ???
ReplyDeleteGreat it working fine, For my urgency it helped a lot.
ReplyDeletejust do it in 2 line after initialize the datepicker.
ReplyDelete$('.date-pick').datepicker({ dateFormat: 'yy-mm-dd' });
$('.date-pick').datepicker("setDate", new Date());
Helpful, thanks
ReplyDeleteHelpful, thank you
ReplyDelete