As in title, I need to convert (for example) "Thu, 08 Oct 2020 08:32:44 GMT" format to Y-m-d H:i:s in php.
Anyone know how to do that ?
As in title, I need to convert (for example) "Thu, 08 Oct 2020 08:32:44 GMT" format to Y-m-d H:i:s in php.
Anyone know how to do that ?
Use DateTime::createFromFormat
. It allows to specify the format of the input, and with format
you can specify the desired output:
$dateTime = DateTime::createFromFormat('D, d M Y H:i:s e', 'Thu, 08 Oct 2020 08:32:44 GMT');
echo $dateTime->format('Y-m-d H:i:s'); // 2020-10-08 08:32:44
The documentation provides all the formatting characters you can use.
Make use of strtotime
and date
function See Demo
$ php -r '$str="Thu, 08 Oct 2020 08:32:44 GMT"; print date("Y-m-d H:i:s",strtotime("$str"));'
2020-10-08 08:32:44
Better readable version
<?php
$str="Thu, 08 Oct 2020 08:32:44 GMT";
print date("Y-m-d H:i:s",strtotime("$str"));
?>
Just use date
to convert that. Pass the format string and the date in Unix timestamp (you can convert it using strtotime
).
Example:
$date = "Thu, 08 Oct 2020 08:32:44 GMT";
$newDate = date("Y-m-d H:i:s", strtotime($date));