CodeIgniter Forums
ordering by date time stamp from todays 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: ordering by date time stamp from todays date (/showthread.php?tid=40924)



ordering by date time stamp from todays date - El Forum - 04-22-2011

[eluser]R_Nelson[/eluser]
i got my calendar working very nice and what i would like to do is sort the dates in the DB from today till i find 1 then use that info to make a next show box on my right side bar i can get the DB to show me all the dates and i know i can use limit 1 to get just one but how do i make Mysql pick the next day that there is a show booked for including that day!


ordering by date time stamp from todays date - El Forum - 04-22-2011

[eluser]R_Nelson[/eluser]
I ended up solving it my self this is the query
Code:
$this->db->where('date >=',date('Y-m-d'))->order_by('date','asc');    
$data['query'] = $this->db->get('calendar');

i know i can put ->limit(1) at the end of my chain and even chained in the get() but i decided i want to take it a step further and see if the DB date is today and if it is i'm gonna display that one and the next show if not i'm not gonna care about anything else that shows up!


ordering by date time stamp from todays date - El Forum - 04-22-2011

[eluser]Twisted1919[/eluser]
Mysql has some specific functions to work with dates, for example, you could do:
Code:
$this->db->where('DATE(`date`) >=','DATE(NOW())',false)->order_by('date','asc');
Just a thought.