tags:

views:

51

answers:

3

Hi how do I group by and order by a datetime field with CakePHP?

A: 

Did you already make an attempt and did it fail?

I don't have a CakePHP installation around to verify, but my first guess would be to state in the controller:

$this->Model->find("all", array('order'=>'Model.datetimeFieldName'));

I'd expect Cake to handle the ordering.

Brelsnok
A: 

An even better way to do this is to specify the order in the Model.

http://book.cakephp.org/view/440/order

You can still of course override that in the controller later.

PawelMysior
+5  A: 
$this->Post->find('all', array(
    'order' => array('Post.date' => 'DESC'),
    'group' => 'Post.date'
));
TiuTalk