Reputation: 659
I'm creating a timeline and I'm nearly finished. I want that the color of the date for each timeline event is the same beside if the date is "today".
So I need something like:
@if($event[$i]->created_at->format('d.m.Y') == *code or variable that says its today*)
....
@endif
But I couldn't figure out what I can do to save the todays date in a variable.. Does anybody knows a solution for this?
thanks!
Upvotes: 20
Views: 23089
Reputation: 813
You can use whereDate, whereMonth, whereDay, whereYear, whereTime
whereDate()
$users = DB::table('users')
->whereDate('created_at', '2019-11-31')
->get();
whereMonth()
$users = DB::table('users')
->whereMonth('created_at', '10')
->get();
whereDay()
$users = DB::table('users')
->whereDay('created_at', '20')
->get();
whereYear()
$users = DB::table('users')
->whereYear('created_at', '2019')
->get();
whereTime()
$users = DB::table('users')
->whereTime('created_at', '=', '11:20:45')
->get();
Upvotes: 2
Reputation: 4411
you can use Carbon
@if($event[$i]->created_at->format('d.m.Y') == \Carbon::today() )
....
@endif
Upvotes: 6
Reputation: 163768
You can use isToday()
method to check if date is today:
if ($event[$i]->created_at->isToday())
Upvotes: 40