CodeIgniter Forums

Full Version: ordering by date time stamp from todays date
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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!

El Forum

[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!

El Forum

[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.