How to sort field of type VARCHAR in CodeIgniter

1

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

You can already do this in pure SQL like this:

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

However the version of CodeIgniter I'm 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 5.3.7 Version
asked by anonymous 11.05.2018 / 22:37

1 answer

1
___ erkimt ___ How to sort field of type VARCHAR in CodeIgniter ______ qstntxt ___

How to sort fields of type FALSE in class %code% of CodeIgniter?

You can already do this in pure SQL like this:

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

However the version of CodeIgniter I'm using, 3.1.6, does not recognize this function: %code% .

$this->db->order_by ("str_to_date(andamento.dtandamento, '%d-%m-%Y')", 'DESC', FALSE);
  • IC Version: 3.1.6
  • PHP 5.3.7 Version
______ ___ azszpr298322

In the last parameter of the method order_by put %code% to text entered is included with no change in it was written, that is, the data will not be escaped, for 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);
    
___
12.05.2018 / 15:54