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 MySQL union in PHP?
- How to order by a column in MySQL using PHP?
- How to use a variable in a MySQL query using PHP?
- What port to connect to MySQL from PHP?
- How to insert a null value in MySQL using PHP?
- How to change database in MySQL with PHP?
- How to prepare a statement in MySQL using PHP?
- How to list databases in PHP and MySQL?
- How to insert a date into a MySQL database using PHP?
- How to check if a record exists in PHP and MySQL?
See more codes...