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 utf8mb4_unicode_ci in MySQL with PHP?
- How to join tables with PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to write an update query in MySQL using PHP?
- How to count the number of resulting rows in a MySQL database using PHP?
- How to use a MySQL union in PHP?
- How to set a timeout for MySQL query in PHP?
- How to create an SSL connection to MySQL using PHP?
- How to get the last insert ID in PHP MySQL?
- How to fetch data from MySQL in PHP?
See more codes...