Search for birthdays of the month

0

I would like to make a condition where you only display the birthdays of the month. My controller looks like this:

public function index()
{
    $ultimoDia = date("t", mktime(0,0,0,date('m'),'01',date('Y')));
    $condicoes['order'] = array('Funcionario.NomFun' => 'ASC');
    $condicoes['conditions'] = array(
        'Funcionario.SitAfa <>' => 7,
        'Funcionario.datNasc >=' => date("m").'-01',
        'Funcionario.datNasc <=' => date("Y-m").'-'.$ultimoDia
    );
    $condicoes['limit'] = 60;
    var_dump($condicoes['conditions']);
    $this->paginate = $condicoes;
    $this->set('aniversariantes', $this->paginate());
}

But it does not work it does not list anything because the string it returns is:

'Funcionario.datNasc >=' => string '09-01' (length=5)
'Funcionario.datNasc <=' => string '2015-09-30' (length=10)

and the datNasc table returns the complete employee date ex: string '2015-09-18'.

    
asked by anonymous 18.09.2015 / 14:39

2 answers

1

Try to make the condition only with the month, like this:

$condicoes['conditions'] = array(
    "Funcionario.SitAfa <>" => 7,
    "DATE_FORMAT(Funcionario.datNasc, '%m') = DATE_FORMAT(NOW(), '%m')"
);
    
18.09.2015 / 14:51
0

Try this:

public function index(){
    $ultimoDia = date("t", mktime(0,0,0,date('m'),'01',date('Y')));
    $condicoes['order'] = array('Funcionario.NomFun' => 'ASC');
    $condicoes['conditions'] = array(
        'month(Funcionario.datNasc) =' => date("m"),
    );
    $condicoes['limit'] = 60;
    var_dump($condicoes['conditions']);
    $this->paginate = $condicoes;
    $this->set('aniversariantes', $this->paginate());
}
    
29.09.2015 / 22:04