DATE_FORMAT() in query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

DATE_FORMAT() in query?

Post by f1nutter »

Hi,

I was having some trouble with formatting dates, and found this post very useful.

http://www.devnetwork.net/forums/viewto ... light=date

It suggests using MySQL to format the dates instead of PHP, fair enough. So, I am using DATE_FORMAT() but want to know how to use it in a query. This doesn't work (the mysql_query prints the die statement).

Code: Select all

SELECT DATE_FORMAT(Date, %e %b) FROM table;
where Date is a column name.

What to do?

Thanks.
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

:oops: Sorry for wasting your time :oops:
If in doubt, read the manual!

I forgot the quotes around the formatting, and should have 'saved' the output as something else.

For future reference :

Code: Select all

SELECT DATE_FORMAT(col1, '%e %b') AS MyDate FROM table;

// query

$date = $rowї"MyDate"];
:oops:
Post Reply