Formating a table date field from the Model in Codeigniter

Posted by Landitus on Stack Overflow See other posts from Stack Overflow or by Landitus
Published on 2010-06-13T07:00:31Z Indexed on 2010/06/13 7:02 UTC
Read the original article Hit count: 209

Filed under:
|
|
|

Hi, I', trying to re-format a date from a table in Codeigniter. The Controller is for a blog. I was succesfull when the date conversion happens in the View. I was hoping to convert the date in the Model to have things in order.

Here's the date conversion as it happens in the View. This is inside the posts loop:

 <?php foreach($records as $row) : ?>

  <?php 
   $fdate = "%d <abbr>%M</abbr> %Y";
   $dateConv = mdate($fdate, mysql_to_unix($row->date));
  ?>

  <div class="article section">
   <span class="date"><?php echo $dateConv ;?></span>

... Keeps going ...

This is the Model:

    class Novedades_model extends Model {

 function getAll() {
  $this->db->order_by('date','desc'); 
  $query = $this->db->get('novedades');

  if($query->num_rows() > 0) {
   foreach ($query->result() as $row) {
    $data[] = $row;
   }
  }
  return $data;
 }
}

How can I convert the date in the Model? Can I access the date key and refactor it?

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about date