Formating a table date field from the Model in Codeigniter
- by Landitus
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?