Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to datetime field with date condition only in cakephp

In cakephp query conditions, where i have only date which have to meet the conditions with datetime field of table. suppose i have date only(2013-09-21) and field is (2013-09-21 07:45:23). i have get problem to give the condition here.

like image 204
Sujan Avatar asked Oct 22 '13 11:10

Sujan


2 Answers

If @Aryan 's solution doesn't work because you need to convert between formats at the database, then you want to use the MySQL function DATE. This would change the find example to be this:

$row = $this->Model->find('all',
                    array('fields' => array('........'),
                    'conditions' => array(
                        'DATE(Story.created) >' => $date)));
like image 138
AgRizzo Avatar answered Oct 08 '22 01:10

AgRizzo


$date_string = "2013-09-21";
$new_date = date('Y-m-d H:i:s', strtotime($date_string));
$row = $this->Model->find('all',
                    array('fields' => array('........'),
                    'conditions' => array(
                        'Story.created >' => $new_date)));
like image 31
karmicdice Avatar answered Oct 08 '22 03:10

karmicdice