Home > Database > Mysql Tutorial > body text

How to Convert ISO8601 Datetime to MySQL DATE Format in PHP?

DDD
Release: 2024-10-25 08:21:02
Original
197 people have browsed it

How to Convert ISO8601 Datetime to MySQL DATE Format in PHP?

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!