Reputation:
I have just started to use php active record to select rows between 2 dates, it seems to work on some tests but on some it fails, this is what i have so far
$to = $_POST['to'];
$from = $_POST['from'];
$visitors = Visitors::find('all', array('conditions' => "visitdate >= '$from' AND visitdate <= '$to'"));
is there a between clause available?
Thank you
Upvotes: 0
Views: 1228
Reputation: 11820
You'll need to designate visitdate
as a DATE
in order to compare the strings.
$visitors = Visitors::find('all', array('conditions' => "DATE(visitdate) BETWEEN '$from' AND '$to'"));
More here: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between
Upvotes: 2