Easiest way to sort by date... |
[eluser]codelearn[/eluser]
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? Thanks.
[eluser]Armchair Samurai[/eluser]
I'd do it like this Code: SELECT foo
[eluser]Developer13[/eluser]
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: http://dev.mysql.com/doc/refman/5.0/en/s...ion_substr
[eluser]codelearn[/eluser]
Code: $this->db->where('SUBSTR(date,1,7)',$_POST['date_sort']); Excellent as always, thanks guys. |
Welcome Guest, Not a member yet? Register Sign In |