I made a PHP website that use a SQL database for the information.
Now I want to show the date of the last update of that database.
My code works great, except, when I run the command in phpMyAdmin I get the (right) date:
UPDATE_TIME
2024-08-10 10:40:08
The website show the date of today:
update: 13-08-2024
$sql = "SELECT update_time FROM information_schema.tables WHERE TABLE_NAME = 'katten'";
$tableStatus = mysqli_query($link, $sql);
while ($array = mysqli_fetch_array($tableStatus))
{
$updatetime = $array['UPDATE_TIME'];
}
echo date ('d-m-Y', $updatetime);
What I’m doing wrong?
2
Answers
The issue you’re encountering stems from the fact that the UPDATE_TIME value retrieved from the database is a string (formatted as YYYY-MM-DD HH:MM:SS), not a Unix timestamp, which the date() function expects. To fix this, you need to convert the UPDATE_TIME string into a Unix timestamp before passing it to the date() function.
Here’s how you can modify your code:
You need to feed a timestamp value the PHP
date()
function as in: