0
echo `{{$result->created_at}}`  

result is 2018-06-23 08:05:14
but I want to echo just date. not time
I mean echo only 2018-06-23 not 2018-06-23 08:05:14

Cœur
  • 37,241
  • 25
  • 195
  • 267
ti shohagh
  • 11
  • 5

4 Answers4

4

It's a Carbon instance. The recommended option is simply

{{ $result->created_at->toDateString() }}

Carbon docs: https://carbon.nesbot.com/docs/#api-formatting

Rwd
  • 34,180
  • 6
  • 64
  • 78
Joel Hinz
  • 24,719
  • 6
  • 62
  • 75
1

This is pretty simple, directly escape date to whichever format you want like in the example below

 {{ date('Y-m-d', strtotime($result->created_at))}}
athulpraj
  • 1,547
  • 1
  • 13
  • 24
0

You may handle this on the PHP side by just using substr:

echo {{ substr($result->created_at, 0, 10) }}

There are also ways that you could handle the formatting on the MySQL side, e.g. by using DATE_FORMAT:

DATE_FORMAT(created_at, '%Y-%m-%d')
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

you can use laravel Accessor by put the following method inside your model:

public function getCreatedAtAttribute($date)
{
    return $date->format('Y-m-d');
}
Rwd
  • 34,180
  • 6
  • 64
  • 78
ali
  • 832
  • 6
  • 11