5

How can I insert an MM/DD/YYYY format date into an MySQL database using PHP?

2 Answers 2

25

This can be done using STR_TO_DATE.

Example:

INSERT INTO useless_table (id, date_added) VALUES(
            1, STR_TO_DATE('03/08/2009', '%m/%d/%Y'));

EDIT: Please also consider MarkR's solution, because it's the right thing to do[tm].

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

1 Comment

The table is probably pretty usefull
7

MySQL support ISO-8601 date/time values, and no others. If you need to use some other whacky format (for example, because you have American customers who expect wonky dates), you need to do the conversion yourself.

Just live with it, ISO-8601 is the one true date format.

1 Comment

"Just live with it" so you think the ISO chose a date format that America could not use even though there are many Americans in the ISO

Your Answer

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