• support@answerspoint.com

CakePHP Retrieving rows for the current month

2618

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


0
$this->find('all', array(
    'conditions' => array('MONTH(Tbsession.timestamp)' => date('n'))
));
  • answered 8 years ago
  • G John

0

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

    Facebook Share        
       
  • asked 9 years ago
  • viewed 2618 times
  • active 9 years ago

Best Rated Questions