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 set a timeout for MySQL query in PHP?
- How to use multiple prepared statements in PHP and MySQL?
- How to output XML from MySQL using PHP?
- How to use a variable in a MySQL query using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to use a MySQL union in PHP?
- How to export data from MySQL to Excel using PHP?
- How to create an SSL connection to MySQL using PHP?
- How to get table column names in PHP MySQL?
- How to get the version of MySQL using PHP?
See more codes...