Converting ISO8601 to MySQL DATE Format in PHP
When working with dates, it is often necessary to convert between different formats. ISO8601 and MySQL DATE are two common formats used in web development. This guide demonstrates how to convert a date in ISO8601 format (e.g., 2014-03-13T09:05:50.240Z) to MySQL DATE format (e.g., 2014-03-13) using PHP.
To convert an ISO8601 date to MySQL DATE format, follow these steps:
Here's an example code snippet that demonstrates the conversion:
1 2 3 |
|
In this example, $fixed will be assigned the value '2014-03-13', which is the MySQL DATE representation of the ISO8601 date $date.
Note: If strtotime returns 0, it means the date is invalid. You can use a workaround by parsing the ISO8601 string and extracting the date part:
1 2 3 |
|
The above is the detailed content of How to Convert ISO8601 Date to MySQL DATE Format in PHP?. For more information, please follow other related articles on the PHP Chinese website!