jquery datepicker date format

If you are using the jquery datepicker and have been displaying the date in the usual mysql date format, you probably will find it annoying that the date picker gives you the slash date format back. Here is how to keep the mysql date dash format all throughout.

var queryDate = '2012-01-10',
    dateParts = queryDate.match(/(d+)/g)
    realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);  
                                    // months are 0-based!

$('#datePicker').datepicker({ dateFormat: 'yy-mm-dd' }); // format to show
$('#datePicker').datepicker('setDate', realDate);

The code above will translate the mysql date to do the initial setup, then use the dash format for the text field.

Ref: http://stackoverflow.com/questions/1953840/datepickersetdate-issues-in-jquery

One thought on “jquery datepicker date format

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s