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 get the first row of a result in MySQL using PHP?
- How to output XML from MySQL using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to use a MySQL union in PHP?
- How to generate a UUID in MySQL using PHP?
- How to get the version of MySQL using PHP?
- How to write an update query in MySQL using PHP?
- How to create an SSL connection to MySQL using PHP?
- How to join tables with PHP and MySQL?
See more codes...