Reputation: 253
I have an array that return the following date time:
$item['created_at'] => "2015-10-28 19:18:44"
And I need this outuput:
"2016-08-10T13:15:00.000+10:00"
Exist any function to convert this date?
Upvotes: 0
Views: 926
Reputation: 341
Try this:
$dt = new \DateTime('2015-10-28 19:18:44', new \DateTimeZone('Europe/London'));
dd($dt->format('c')); // string '2015-10-28T19:18:44+00:00' (length=25)
Alternatively take a look at Carbon
Upvotes: 2
Reputation: 10219
You can use Laravel's accessors to get "reformatted" created_at
.
public function getCreatedAtAttribute($value)
{
//Since Laravel uses Carbon you can do.
return $value->format('c');
}
This way anytime you do something like $model->created_at
it will return modified created_at
.
If you want to change datetime format for created_at
in your database as well, you can use mutators.
More information you can find on the Laravel's docs page.
Upvotes: 0