2011-08-24 56 views
0

我有下面的代碼與今天的時間戳檢索行:CakePHP的檢索行當月

$interactives_presented_today = $this->find('count', 
        array('conditions' => array('Tbsession.timestamp LIKE' => date("Y-m-d") . "%", 
               'Tbsession.action LIKE' => "%Interactive", 
               'Tbsession.username' => $user_id, 
              )) 
       ); 

現在,我想和這個月的時間戳檢索行。有任何想法嗎?非常感謝您的幫助! :)

+0

嘗試從''Tbsession.timestamp每月提取和比它與當月比較 – Rikesh

+0

感謝您的答覆,但我覺得這是我的問題,你知道如何在CakePHP中提取它? – Emkey

+0

讓我有'Tbsession.timestamp'的價值! – Rikesh

回答

6
$this->find('all', array(
    'conditions' => array('MONTH(Tbsession.timestamp)' => date('n')) 
)); 
2

這種獲取不到1個月的所有行:

$this->find('all',array(
    'conditions'=>array($this->alias.'.timestamp >'=>date('Y-m-d', strtotime("-1 month")) 
)); 

,如果你想獲得這個月:

$this->find('all',array(
    'conditions'=>array($this->alias.'.timestamp >'=>date('Y-m-00') 
)); 
+0

這將得到上個月的所有行,不是嗎? – Emkey

+0

它會得到小於1個月的所有行。我會編輯我的答案。 –

+0

你認爲我的時間戳值是類似於2010-09-23 13:04:58? – Emkey

1

你可以使用mysql DATE_FORMAT()函數。

$this->find('all',array(
'conditions'=> array('DATE_FORMAT(Tbsession.timestamp,"%m") = "'.date("m").'"') 
));