Find birthday girls of the month

Asked

Viewed 58 times

0

I would like to make a condition where only show the birthday of the month. My controller looked 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 table datNasc returns the full employee date ex: string '2015-09-18'.

2 answers

1

Try to make the condition only with the month, so:

$condicoes['conditions'] = array(
    "Funcionario.SitAfa <>" => 7,
    "DATE_FORMAT(Funcionario.datNasc, '%m') = DATE_FORMAT(NOW(), '%m')"
);
  • Perfect guy, thank you so much.

0

Try it this way:

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());
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.