There are many ways to get only date, but you can use Date Casting.
protected $casts = [
'start_date' => 'datetime:Y-m-d',
'finish_date' => 'datetime:Y-m-d',
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
HI, I saved two fields to db using carbon, and i'm getting 2021-08-22 00:00:00 how to get only the date without the time ? Thanks in advance !
in Event model
public function setStartDateAttribute($date)
{
return $this->attributes['start_date'] = Carbon::createFromFormat("m/d/Y", $date)->format('Y-m-d');
}
public function setFinishDateAttribute($date)
{
return $this->attributes['finish_date'] = Carbon::createFromFormat("m/d/Y", $date)->format('Y-m-d');
}
in Controller
$event->start_time = $request->start_time;
$event->finish_time = $request->finish_time;
in Blade when showing the start_time and finish_time field
<tr>
<td>Start Date</td>
<td>{{ $event->start_date }}</td>
</tr>
<tr>
<td>Finish Date</td>
<td>{{ $event->finish_date }}</td>
</tr>
date saved in db like 2021-08-22 00:00:00
in blade you can use this way
<td>{{ $event->finish_date->format('Y-m-d') }}</td>
Please or to participate in this conversation.