Easiest way to sort by date... - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Easiest way to sort by date... (/showthread.php?tid=4793) |
Easiest way to sort by date... - El Forum - 12-16-2007 [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. Easiest way to sort by date... - El Forum - 12-16-2007 [eluser]Armchair Samurai[/eluser] I'd do it like this Code: SELECT foo Easiest way to sort by date... - El Forum - 12-16-2007 [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/string-functions.html#function_substr Easiest way to sort by date... - El Forum - 12-16-2007 [eluser]codelearn[/eluser] Code: $this->db->where('SUBSTR(date,1,7)',$_POST['date_sort']); Excellent as always, thanks guys. |