Sort Birthdays by Day

Asked

Viewed 93 times

2

Guys, I needed a help to display on the screen the Birthday of the Month ordered by the day, in the bank he pulls the information from Senior so the date comes ex: 1970-10-30, in my controller is like this:

public function index()

{
    $condicoes['order'] = array('Funcionario.data_nascimento' => 'ASC');
    $condicoes['conditions'] = array(
        'Funcionario.situacao_afastamento <>' => 7,
        "DATE_FORMAT(Funcionario.data_nascimento, '%m') = DATE_FORMAT(NOW(), '%m')"
    );
    $condicoes['limit'] = 59;
    $this->paginate = $condicoes;
    $this->set('aniversariantes', $this->paginate());
}

In this condition he first orders the date of the year :( and then the date of the month.

1 answer

1

You can do it like this:

$condicoes['order'] = array('DAY(Funcionario.data_nascimento) => 'ASC')

  • Hello, so I tried it an hour but it doesn’t validate if I put it that way. :(

  • As well as validation ?

  • It skips that condition, and displays employees randomly.

  • What kind of field data_nascimento ?

  • Field of type DATE

  • 1

    Are you using any datatable ?

  • 1

    I ended up doing it in the hand anyway, thanks for the help. was like this: [$aniversariantes = $this->funcionario->query("select matricula, nome, data_nascimento, data_admissao, local_id from 002_funcionarios WHERE situacao_afastamento <> 7 and Extract(Month from data_nascimento) = DATE_FORMAT(NOW(), '%m') order by Extract(Month from data_nascimento), Extract(day from data_nascimento)"); ]

Show 2 more comments

Browser other questions tagged

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