Converting ISO8601 to MySQL DATE Format in PHP
Q: How to convert the ISO8601 formatted datetime '2014-03-13T09:05:50.240Z' to the MySQL DATE formatted '2014-03-13' in PHP?
A: Here's a method that utilizes PHP's strtotime and date functions:
<code class="php">$date = '2014-03-13T09:05:50.240Z'; $fixed = date('Y-m-d', strtotime($date)); echo $fixed; // Outputs '2014-03-13'</code>
For detailed documentation of the date function, refer to: http://php.net/manual/en/function.date.php
Alternatively, if strtotime returns 0, try this modified version:
<code class="php">$date = '2014-03-13T09:05:50.240Z'; $fixed = date('Y-m-d', strtotime(substr($date,0,10))); echo $fixed; // Outputs '2014-03-13'</code>
The above is the detailed content of How to Convert ISO8601 Datetime to MySQL DATE Format in PHP?. For more information, please follow other related articles on the PHP Chinese website!