user1405631
user1405631

Reputation:

PHP Active Record Find Rows Between 2 Dates

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

Answers (1)

sbeliv01
sbeliv01

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

Related Questions