I have a MySQL DB table with a column with a name "timestamp", type timestampand attribute on update CURRENT_TIMESTAMPand a default value CURRENT_TIMESTAMP.
If I add an entry to the table, specifying other values, but not a timestamp, then the timestamp will automatically be added as 2016-12-28 17:02:26.
In PHP, I query the table using the following query
SELECT * FROM history WHERE user_id = 9 ORDER BY timestamp ASC
The result of the query is stored in $rows, and I use foreachto create an array with some other formatted values. I'm trying to format a timestamp in the date of the 24-hour time in the UK dd/mm/yy, HH:MM:SS.
I tried the functions date()and strftime()as follows:
$formatted_datetime = strftime("%d %m %y %H %M %S", $row["timestamp"]);
$formatted_datetime = date("d/m/y, H:i:s", $row["timestamp"]);
Both of them lead to the following notification, and the time of the date is displayed incorrectly, like 01 01 70 00 33 36:
Note. Invalid numeric value found in / home / ubuntu / workspace / pset 7 / public / history.php on line 20
I am new to PHP and MySQL, and so far, none of the other issues or documentation that I have seen successfully handled this conversion. I do not understand why it strftime()does not work, and how to do it correctly?