Welcome Guest, Not a member yet? Register   Sign In
mysql date range
#1

[eluser]Unknown[/eluser]
hi

I've had a look around here and the rest of the internet to try to find a solution of how to do a range of dates with active record. I want to do it the first style of the two below, I have tested out with explain and this is way quicker, but active record genertates the second kind.

where $start_date < dateField < $end_date


where $start_date < dateField AND dateField < $endDate

try and do a MySQL EXPLAIN on the two queries above and you can see how much exponentially slower the second one is



they both return the same results but the second one is way slower. exponnentially slower because you are searching on the same field twice. if this is the only way with active record it seems like a flaw. for reference I laid out my active record in the below format

I create the select statement with the layout of

$items->where('date_created >', '2011-02-26');
$items->where('date_created <', '2011-02-29 ');

i also tried the below which was really slow

$dateRange = '2011-02-26 < `e`.`start_date_only` < " . '2011-02-29 ', false)

$this->db->where($dateRange, NULL, FALSE);


anyone have any ways around this to keep a decent speed without ditching active record and writing it manually?
#2

[eluser]CroNiX[/eluser]
Did you try putting the whole thing in the first parameter?
Code:
->where("date_created BETWEEN '$start_date' AND '$end_date'")




Theme © iAndrew 2016 - Forum software by © MyBB