Take the 2-minute tour ×

I am using jQueryUI datepicker and making sure that the date, mm/dd/yyyy is shown to the user so they understand what they entered is correct. My only problem is I don't understand how to then take that date and format it to go into mysql date field correctly?

share|improve this question

4 Answers 4

up vote 0 down vote accepted

That's pretty easy if you know a little PHP.
Because PHP being a string manipulation language, it is a must to know some string manipulation basics.

You can use strpos() function to locate position of / symbol and then use substr() to get numbers and then use . concatenation operator to get date parts in order

You can use very handy explode() function, to get date parts into array and then combine them using some variable interpolation, like this:

$d          = explode("/",$date);
$date_mysql = "$d[2]-$d[0]-$d[1]";

When mastered your string manipulation skills, you can start with real powerful voodoo of regular expressions.

share|improve this answer
Thank you for help. –  pertrai1 Sep 9 '11 at 13:42

You can use STR_TO_DATE function in mysql.

$date is the variable that came from Jquery via Ajax, holding the date that user picked up.

Insert into tableName Values('bla', 'bla', STR_TO_DATE($date))

share|improve this answer

Convert your MM/DD/YYYY string to ISO 8601 format, YYYY-MM-DD, and then pretty much any database (including MySQL) will interpret your date properly.

share|improve this answer


$date = date('Y-m-d', strtotime($old_date_format));
share|improve this answer

Your Answer


