views:

25

answers:

2

I'm trying to change this timestamp

2010-08-02 00:28:20

to month/day/year -

08/02/10

..in the query (I know that doing it in the query is faster).

$sql = "SELECT * FROM posts ORDER BY post_date DESC";

I tried using the DATE_FORMAT() in the query many ways but I can't seem to get it right.. Can someone please share how to do this?

+3  A: 

Using the manual on DATE_FORMAT():

SELECT DATE_FORMAT(post_date, "%m/%d/%y");
Pekka
Thanks, that's what I've been using but the format doesn't change.$sql = "SELECT *, DATE_FORMAT(post_date, '%m/%d/%y') FROM posts ORDER BY post_date DESC LIMIT $start, $limit";I get parse error with double quotes.
Cyber Junkie
Mate, nvm, It works now! I was probably doing something else wrong. Thanks again! :)
Cyber Junkie
@Cyber it must be `SELECT *, DATE_FORMAT(post_date, '%m/%d/%y') as date_f FROM posts ORDER BY post_date...`
Col. Shrapnel
Thanks Col! :) Btw, how to you insert code in replies?
Cyber Junkie
@Cyber using backticks: ```
Pekka
`noted!` thanks :)
Cyber Junkie
A: 

For anyone else experiencing this problem check out http://www.mysqlformatdate.com/

Cyber Junkie