Welcome Guest, Not a member yet? Register   Sign In
Date format
#1

[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?
#2

[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);
#3

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

[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
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB