9

How to convert jquery UI datepicker date format for mysql-phpmyadmin datetime type field (default) format?

please help.

Thanks.

2 Answers 2

21

When you are initializing the date time picker, you can pass the format.

$( ".selector" ).datepicker({ dateFormat: 'yy-mm-dd' });

jQuery UI API Documentation > Datepicker dateFormat


Or after init:

//getter
var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
//setter
$( ".selector" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );

Also according to MySQL Reference Manual:

MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format.

Sign up to request clarification or add additional context in comments.

1 Comment

what about the time? How do you format to yyyy-mm-dd hh:mm:ss and set the today default?
4

From the jQuery UI site:

http://jqueryui.com/demos/datepicker/#date-formats

$(yourInput).datepicker({dateFormat: 'yy-mm-dd'})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.