0

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Do you mind accepting the answer if it is indeed the correct solution to your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.