Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jericopulvera's avatar

Convert datetime to readable date

How do I convert datetime to a readable date?

View

{{ \Carbon\Carbon::createFromFormat('Y-m-d H:i:s',  $event->start)->format('Y-m-d') }}

I wanna convert this 2016-04-14 to this April 14, 2016. is it possible?

Controller

 public function getAcads()
    {
        $events = Calendar::orderBy('start','ASC')->get();

        return view('auth.acads',compact('events'));
    }

0 likes
6 replies
jekinney's avatar

Did you set the start column in the model to be a carbon instance? If so its just

$event->start->toDateString();

Or what ever format you want.

Also use Carbon::parse($start).

1 like
jericopulvera's avatar

@jekinney how do I set start column to be carbon instance in my model?

Calendar model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Calendar extends Model
{
    protected $table = 'calendar';
    protected $fillable = ['title','description','start','end','allDay','color','url','category','repeat_type','repeat_id','user_id',];   


}
spekkionu's avatar
Level 48

I wanna convert this 2016-04-14 to this April 14, 2016. is it possible?

Use 'F j, Y' for the format string instead of 'Y-m-d'

Carbon / DateTime objects use the same formats as the php date function.
http://php.net/manual/en/function.date.php

1 like

Please or to participate in this conversation.