Laravel Date Display created_at All Possible Ways
Hello Coders,
Today's lesson we will learn about display created_at date at different ways in laravel 10 inside blade file. I will clearly explain how can we display dates so that it will be more readable to users. I will discuss from scratch and display all possible output. Let's discover the ways to display dates all ways in laravel 10 in a blade file.
Way 1: Using toFormattedDateString()
{{ $user->created_at->toFormattedDateString() }}
//output: May 18, 2023
Way 2: Using diffForHumans()
{{ $user->created_at->diffForHumans() }}
//output: 3 weeks ago
Way 3: Using toDateString()
{{ $user->created_at->toDateString() }}
//output: 2023-05-18
Way 4: Using toDateTimeString()
{{ $user->created_at->toDateTimeString() }}
//output: 2023-05-18 19:44:37
Way 5: Using toDayDateTimeString()
{{ $user->created_at->toDayDateTimeString() }}
//output: Thu, May 18, 2023 7:44 PM
Way 6: Using toCookieString()
{{ $user->created_at->toCookieString() }}
//output: Thursday, 18-May-2023 19:44:37 UTC
Way 7: Using toIso8601String()
{{ $user->created_at->toIso8601String() }}
//output: 2023-05-18T19:44:37+00:00
Way 8: Using format("Y-m-d")
format() method accepts a custom format compatible with PHP date()
{{ $user->created_at->format("Y-m-d") }}
//output: 2023-05-18
Way 9: Using format("Y/m/d")
{{ $user->created_at->format("Y/m/d") }}
//output: 2023/05/18
Way 10: Using format("Y:m:d")
{{ $user->created_at->format("Y:m:d") }}
//output: 2023:05:18
Thanks. Hope this will easy your task. Please fell free to ask any question about this post.
If you like what you are reading, please think about buying us a coffee as a token of appreciation.
We appreciate your support and are committed to providing you useful and informative content.
We are thankful for your ongoing support