Laravel needs to display only date not the time using the Carbon class
LaravelLaravel 5Laravel 4Laravel Problem Overview
Currently, I am using
> Carbon::now()
It Displays date with the time
> 2015-03-10 23:23:46
But I only need a date
2015-03-10
Laravel Solutions
Solution 1 - Laravel
http://carbon.nesbot.com/docs/#api-formatting
$dt = Carbon::now();
echo $dt->toDateString(); // Equivalent: echo $dt->format('Y-m-d');
Solution 2 - Laravel
Simply use this
Carbon::today()->toDateString()
Solution 3 - Laravel
Get Today's Date in Y-m-d formta as given below,
$dt = Carbon::today()->toDateString(); // Use today to display only date
if you have used $dt = Carbon::today()
only, it will return the timestamp also.
Solution 4 - Laravel
This solution will work for you.
<td>
{{$message->created_at->todatestring()}}
</td>
Solution 5 - Laravel
This is correctly:
$date = Carbon::now();
echo $date->format('Y-m-d');
Solution 6 - Laravel
Or you can use this,
echo Carbon::createFromFormat('Y-m-d H', '1975-05-21 22')->toDateTimeString();
// 1975-05-21 22:00:00
Example,
{{ $post->created_at->toDayDateTimeString()}}
Solution 7 - Laravel
This is very important when you have a critical case for checking due date. Here what you can simply use in your case.
Carbon::now()->format('Y-m-d')
Solution 8 - Laravel
The now helper function creates a new Illuminate\Support\Carbon instance for the current time.
// for the current date
Carbon::now()
// OR
now()
# output
# 2021-07-02 00:00:00
// OR
Carbon::now()->toDateString()
// OR
now()->toDateString()
# output
# 2021-07-02