How to convert MySQL timestamp to d-m-yyyy


Problem :

$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



Solution :

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.


Mysql Tutorials

Mysql Howto..

How to write JAVA CLASS and PHP API to post and read from an existing MySQL database

How to load updated data from database(mysql) without refresh the page? [closed]

How to select specific and distincet number of records in multiple columns?

How do I do mysql join statement on multiple table hierarchy levels?

how to insert xml into mysql from a script?

How to update mysql database changes on database server automatically?

How do I properly iterate through a mysqli_fetch_array (procedural)?

How to prevent duplication of values for a columns pair when doing a MySQL INSERT?

PHP MySQL How to skip displaying a field

How would I write this in MySQL?

How to drop unique in MySQL?

how to get data from cache memory without executing mysql db query

how to call query from another table

MySQL group by and aggregate, how to get the wanted id at the end?

how to use multi-keywords search with php and mysql? [closed]

How to avoid and log down some unexpected thing for db?

Mysql: How to show Realtime display of new inserts and updates to table?

how to get remote mysql database dump to my local machine?

How to send Personal Message using AJAX, PHP and MySQL?

how to improve select performance in mysql?

Flask/SQLAlchemy - How to globally use latin-1 instead of UTF-8?

How to upload a file (csv or text) and read contents in Zope framework

How to use mySQL count using joins?

how to connect to a mySQL instance remotely?

How to insert long Strings into mySQL database using PHP?

How to use “mysql2” gem in Rails 3 application on Windows 7?

how to pull flash video from mysql with php

How can I convert this php mysql code to SQL which is acceptable by SQL server ? [closed]

How to install gem MySQL on Mac OS 10.6.6

How to load mysql dump to hsqldb database?