CakePHP Retrieving rows for the current month
I have to following code to retrieve rows with timestamp of today:
$interactives_presented_today = $this->find('count',
array('conditions' => array( 'Tbsession.timestamp LIKE' => date("Y-m-d") . "%",
'Tbsession.action LIKE' => "%Interactive",
'Tbsession.username' => $user_id,
) )
);
Now, I want to retrieve rows with timestamp of this month. Any ideas? Thanks a lot for any help! :)
2Answer
$this->find('all', array(
'conditions' => array('MONTH(Tbsession.timestamp)' => date('n'))
));
- answered 8 years ago
- G John
You can use the mysql DATE_FORMAT() function.
$this->find('all',array(
'conditions'=> array('DATE_FORMAT(Tbsession.timestamp,"%m") = "'.date("m").'"')
));
- answered 8 years ago
- G John
Your Answer