DEV Community

AquaCat
AquaCat

Posted on

1

【Laravel】How to change the format for date&time in blade file?

When you want to change the format for date&time in Laravel blade files, you can use "format" method.
The conditions are as below.

  • Column name is "updated_at" and its data type for this column is timestamp (ex: "2022-03-22 04:55:01") -In blade file, iterate the variables that is passed by the controller (ex:$post).
<div class="col-4">
 {{$post->updated_at->format('Y/m/d')}}
</div>

Enter fullscreen mode Exit fullscreen mode

What you get in the web browser is as below.("-" is replaced by "/.")

2022/03/22
Enter fullscreen mode Exit fullscreen mode

"Format" method from Carbon class works, too. You create a carbon instance by "Carbon\Carbon::parse()," and then specify the format('Y/m/d') by format method.

<div class="col-4">
  {{Carbon\Carbon::parse($quotes->created_at)->format('Y/m/d')}} 
</div>
Enter fullscreen mode Exit fullscreen mode

To parse date is to take string representation of a date, and returns a unix timestamp.

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay