Reputation: 4093
I have a contact table with date field for birthdate.
Now I would like to show list of birthday within next week. I can show it, but the order is based on the year.
How can I order the data, just based on month and day only?
$sideBarTaskSuggestion =
$this->Project->Contact->find('all', array(
'conditions' => array(
'Contact.group_id' => $this->Session->read('Auth.User.group_id'),
'Contact.birthdate NOT' => null,
'AND' => array(
array('Contact.birthdate NOT' => null),
array('Contact.birthdate + INTERVAL EXTRACT(YEAR FROM NOW()) -
EXTRACT(YEAR FROM Contact.birthdate) YEAR <=' => date('Y-m-d',
strtotime('+1 week'))),
array('Contact.birthdate + INTERVAL EXTRACT(YEAR FROM NOW()) -
EXTRACT(YEAR FROM Contact.birthdate) YEAR >=' => date('Y-m-d')),
)
),
'order' => 'Contact.birthdate DESC'
)
);
Upvotes: 2
Views: 2161
Reputation: 5271
When you say you want 'order the data, just based on month and day only?', I assume you mean:
Then try this:
'order' => 'DAYOFYEAR(Contact.birthdate) DESC'
Upvotes: 4