0

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?

4 Answers 4

0

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.

0
0

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))

0

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.

0

PHP:

$date = date('Y-m-d', strtotime($old_date_format));

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.