PHP活动记录查找2个日期之间的行


PHP Active Record Find Rows Between 2 Dates

我刚刚开始使用php活动记录来选择两个日期之间的行,它似乎在一些测试中有效,但在一些测试上失败了,这就是我迄今为止拥有的

$to = $_POST['to'];
$from = $_POST['from'];
$visitors = Visitors::find('all', array('conditions' => "visitdate >= '$from' AND visitdate <= '$to'"));

有中间条款吗?

感谢

为了比较字符串,您需要将visitdate指定为DATE

$visitors = Visitors::find('all', array('conditions' => "DATE(visitdate) BETWEEN '$from' AND '$to'"));

更多信息:http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between