Welcome Guest, Not a member yet? Register   Sign In
Easiest way to sort by date...

Quick question:

What is the easiest way to return data from a MySQL table and sort it by date.. so if you had a date field (in 2007-12-14 format) what would be the easiest way to say return all the values that were in January?


[eluser]Armchair Samurai[/eluser]
I'd do it like this
FROM bar
WHERE created >= '2008-01'
AND created < '2008-02'
ORDER BY created ASC

If >= 2007-01-01 AND < 2007-02-01 doesn't work,then you could always use MySQL's SUBSTR() function:

Something like this should work:

SELECT * FROM table WHERE SUBSTR(date_field, 0, 7) = '2007-01';

See the following for more information:


Excellent as always, thanks guys.

Theme © iAndrew 2016 - Forum software by © MyBB