CodeIgniter Forums
Date format - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Date format (/showthread.php?tid=43184)



Date format - El Forum - 07-03-2011

[eluser]Perkin5[/eluser]
I'm a beginner developing a blog. It all gone quite well except the MySQL date output is in the form 2011-06-01 and I want it to be in the form 01 June 2011.

I've had a look through the data helper guide but can't see how to convert the format from there.

I'm thinking that it has to be in the database read function which at the moment looks like this:

Code:
$query = $this->db->get('blog');
return $query->result();

Can anyone advise me how to pull it off?


Date format - El Forum - 07-04-2011

[eluser]toopay[/eluser]
Just assign the new date format to the result data...
Code:
// Suppose you have this in your model
$query = $this->db->get('blog');
return $query->result_array();

// In your controller, you can do this
$entries = $this->some_model->some_function();
// suppose you have 'date' as your date column name...
$i = 0;
while ($i < count($entries))
{
   // Since you store your date type with non-unix format, you will need it first
   $old_date = strtotime($entries[$i]['date']);
   $new_date = date('j F Y', $old_date);
   // Then assign it
   $entries[$i]['date'] = $new_date;
   $i++;
}
// To check the new value
var_dump($entries);



Date format - El Forum - 07-04-2011

[eluser]Perkin5[/eluser]
SOLVED. Thank you so much for that - works a treat!


Date format - El Forum - 07-04-2011

[eluser]InsiteFX[/eluser]
If you need to get and rearrange parts of a date there is an easy way to do it!

PHP getdate

InsiteFX


Date format - El Forum - 07-05-2011

[eluser]Perkin5[/eluser]
Very useful additional information - many thanks for that!