How to sort VARCHAR field in Codeigniter

Asked

Viewed 79 times

1

How to sort fields of type VARCHAR in class model codeigniter?

Already achieve in pure SQL that way:

order by strtodate(dtdespesa, '%d-%m-%Y') desc;

However, the version of Codeigniter I am using, 3.1.6, does not recognize this function: strtodate.

$this->db->order_by (strtodate('dtandamento', '%d/%m/%Y')); 
  • IC Version: 3.1.6
  • PHP version 5.3.7
  • Puts codeigniter code forming query with function

  • $this->db->order_by (strtodate('dtandamento', '%d/%m/%Y'));

  • the function is working fine, what is picking up is the order_by

  • have tried: $this->db->order_by("strtodate('dtandamento', '%d/%m/%Y')", 'ASC', FALSE);?

  • @Virgilionovic, I just tried. Gave the same message: Message: Call to Undefined Function strtodate()

  • put all the code!

  • It worked!!! I just added the name of the other table and ordered it the way I wanted. Many thanks @Virgilionovic $this->db->order_by ("str_to_date(tempo.dtandamento, '%d-%m-%Y')", 'DESC', FALSE);

  • Ramiro I put as an answer!

Show 3 more comments

1 answer

1


In the last parameter of the method order_by place FALSE, so that the typed text is included without change in what was written, that is, the data will not be escaped, example:

$this->db->order_by("strtodate('dtandamento', '%d/%m/%Y')", 'ASC', FALSE);

in your specific case:

$this->db->order_by ("str_to_date(andamento.dtandamento, '%d-%m-%Y')", 'DESC', FALSE);

Browser other questions tagged

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