Sorry if this has been asked before. I search for a while and couldn't find an answer that worked.
Basically, I have two datepickers in the UI... From Date and To Date. I want to find entries that belong to that user in that date range.
In my model:
public function getLogData($from,$to) {
$user = $this->getDi()->getShared('session')->get('auth');
$from = gmdate('Y-m-d H:i:s',strtotime($from));
$to = gmdate('Y-m-d H:i:s',strtotime($to));
$logs = $this->find([
"user_id = ".$user->id,
"log_date BETWEEN ".$from." AND ".$to,
"order" => "log_date ASC"
]);
$arr = [];
foreach($logs as $log) {
$log->log_date = $log->getLogDate();
$log->total = $this->getLogTotal($log);
$arr[] = $log;
}
return $arr;
}
No matter what the $from and $to date are, this returns all records for the user. What am I doing wrong?
My find array looks like this with the vars in place:
[0]=> "user_id = 3"
[1]=> "log_date BETWEEN 2016-02-11 07:00:00 AND 2016-02-14 07:00:00"
["order"]=> "log_date ASC"