Monday, May 28, 2012

find birthday ignoring the year

Hello I am trying to find upcoming birthdays for users. within next 30
days, 30-90 days, 90-120 days , etc
I do not need the year to be compaired.
The birthdate field is Y-m-d format.
in my model I have the following but I do not need the year to be
checked so what I have does not work. I have tried several variations
but can not get this to work..

function getBirthdaysFromDates($type1, $session_school_id){
if($type1 == '30') {
//set condition of date range
$from = date('Y-m-d');
$to = date('Y-m-d', strtotime('+30 days'));
$cond = array('User.birthdate BETWEEN ? AND ?' => array($from,
$to), 'Usermembership.school_id' => $session_school_id,
'Usermembership.status' => 1);
}elseif($type1 == '60'){
//set condition of
date range
$from = date('Y-m-d', strtotime('+30 days'));
$to = date('Y-m-d', strtotime('+60 days'));
$cond = array('User.birthdate BETWEEN ? AND ?' => array($from,
$to), 'Usermembership.school_id' => $session_school_id,
'Usermembership.status' => 1);

}
return $cond;
}

In the Controller

$cond = $this->Usermembership->getBirthdaysFromDates($this-
>data['Usermembership']['type'], $this->params['pass'][0],
$session_school_id);
$this->set('usermemberships', $this->paginate($cond));

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: