Quantcast

find birthday ignoring the year

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

find birthday ignoring the year

Robert Gravel
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: find birthday ignoring the year

Robert Gravel
Anyone have a solution to this?  Thanks

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: find birthday ignoring the year

AD7six


On Tuesday, 29 May 2012 17:58:25 UTC+2, rockbust wrote:
Anyone have a solution to this?  Thanks

Why don't you store the user's birthday (MM/DD) and search on that instead of or in addition to their birthdate.

You could also just use mysql's date functions ala (all users born in february):

    select * from users where MONTH(birthdate) = 2;

To use sql functions in queries - either type the whole thing as a string, or use a dbo expression object (try first, ask second - with code).

AD

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: find birthday ignoring the year

Robert Gravel
Thanks AD,

After playing around with the date function I did a search by the
month

array('MONTH(User.birthdate)' => date('m') )
array('MONTH(User.birthdate)' => date('m', strtotime('+30 days')) )
array('MONTH(User.birthdate)' => date('m', strtotime('+60 days')) )

works fine

--
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
[hidden email] For more options, visit this group at http://groups.google.com/group/cake-php
Loading...