Get most recent 7 records order by second

I was trying to select records from within the last 7 days with this:


SELECT id, date_added
FROM table
WHERE DATE( date_added ) > ( NOW( ) - INTERVAL 7 DAY )
ORDER BY date_added DESC

which returned this:

18 May 24, 2014
19 May 24, 2014
11 May 18, 2014
12 May 18, 2014
13 May 18, 2014
14 May 18, 2014
15 May 18, 2014
16 May 18, 2014

but you can see id 18 and 19 and 11 - 16 are out of order, I think because my query is not considering the hour : minute : second part of my datetime datatype.

can you please tell me how I can get the data to return with the ids 19 - 11 in order? Thanks in advance.

Could you please show us the raw output of that query? The output you posted has been processed in some way because a MySQL datetime field looks like YYYY-mm-dd HH:ii:ss, not like what you posted.

You figured it out!

I scaled down the query above to post it, but the whole select statement looked like this:

SELECT id, heading, DATE_FORMAT( date_added, ‘%M %d, %Y’ ) AS date_added

thanks for the second pair of eyes.

Hehe. Glad I could help :smiley: