php-mysqlHow to convert a MySQL timestamp to a datetime in PHP?
To convert a MySQL timestamp to a datetime in PHP, you can use the strtotime() function. This function takes a string as an argument and returns a Unix timestamp.
$timestamp = strtotime('2020-02-14 10:00:00');
echo date('Y-m-d H:i:s', $timestamp);
Output example
2020-02-14 10:00:00
Code explanation
strtotime(): This function takes a string as an argument and returns a Unix timestamp.date(): This function takes two arguments, the format of the output and the timestamp.
Helpful links
More of Php Mysql
- How to use a variable in a MySQL query using PHP?
- How to get a single value from query in PHP MySQL?
- How to use a MySQL union in PHP?
- How to get the version of MySQL using PHP?
- How to create an SSL connection to MySQL using PHP?
- How to update to null value in MySQL using PHP?
- How to output XML from MySQL using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to check the result of an insert in PHP and MySQL?
- How to escape a string for MySQL in PHP?
See more codes...