简体   繁体   中英

Inserting mm/dd/yyyy format dates in MySQL

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

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].

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM