Date format in list view of simple Module

edited August 2015 in Modules
Hi,
I have adjusted the MY_config.php to format the date in "german" way as d.m.Y.
In the create and edit view of my modules everything is working fine. But in the list view the date is displayed as yyyy-mm-dd
How can I achieve that the date is displayed correctly?

Comments

  • edited August 2015
    You'll need to modify your list_items method on your model. You could use the MySQL DATE_FORMAT function, however, that will mess up sorting because d.m.Y is a format that would be sorting on months first. The recommended way would be to loop through the data and change it and then apply any sorting:
    function list_items($limit = NULL, $offset = NULL, $col = 'date_added', $order = 'desc', $just_count = FALSE) { $data = parent::list_items($limit, $offset, $col, $order); if (!$just_count) { foreach($data as $key => $val) { $data[$key]['date_added'] = english_date($data[$key]['date_added'], TRUE); } } if ($col == 'date_added') array_sorter($data, $col, $order); return $data; }
  • edited 4:01AM
    ok. that worked. thank you!
  • edited 4:01AM
    There was one line I forgot to add and that was the sorting for that field if it is the date_field. I added it above.
Sign In or Register to comment.