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
  • 34,719
  • 24
  • 185
  • 251
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
  • 31,835
  • 6
  • 52
  • 69
Joel Hinz
  • 23,685
  • 6
  • 57
  • 74
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,529
  • 1
  • 11
  • 23
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
  • 451,927
  • 24
  • 239
  • 318
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
  • 31,835
  • 6
  • 52
  • 69
ali
  • 782
  • 5
  • 11