$newTime = "TIME_FORMAT(date, '%e-%M-Y') AS date";
$result = mysqli_query($connect, "SELECT id, firstname, lastname, email, text, $newTime FROM gastenboek");
This is some information selecten from the database, i want to convert the sql timestamp to php days - months - years (22-11-2013).
The query works fine but date = NULL
it seems that my query is wrong, because when i do SELECT * FROM gastenboek it all works fine.
Error code: Notice: Trying to get property of non-object
I already googled the problem but i can't find the solution.
Sorry for my bad english, and thanks in advanced!
Greetings from Holland
You need to use DATE_FORMAT
instead of TIME_FORMAT
. And I think your format string needs to be tweaked. Try this:
DATE_FORMAT(date, '%e-%c-%Y') AS date
The docs for TIME_FORMAT
say:
This is used like the DATE_FORMAT() function, but the format string may contain format specifiers only for hours, minutes, seconds, and microseconds. Other specifiers produce a NULL value or 0.
you have a , (comma) right before FROM (after $newtime)
Assuming the mysql timestamp will be equivalent as NOW() function output, you can use the following method:
SELECT concat(day(now()),"-",month(now()),"-",year(now())) as date
Not the most efficient approach but will get the job done.