I have to compare two dates in a list.blade.php like
if today's date is greater than or equal to expiry date then do something else do something.
here is the code:
@php
use Carbon\Carbon;
$today_date = Carbon::today();
@endphp
@foreach ($entries as $k => $entry)
@if($today_date >= $entry->expire_date)
// do something
@else
// do something
@endif
@endforeach
Date format: YYYY-MM-DD
But this is not working.
Please help
Thanks
EDIT:
I tried this:
<?php
use Carbon\Carbon;
$today_date = Carbon::now();
foreach ($entries as $k => $entry) {
$expire_date = Carbon::createFromFormat('Y-m-d', $entry->expire_date);
}
?>
and it gives me error like: image
One more thing expire_date
is of text type in my database so this might be the problem.
The
false
parameter is optional and indicates if you want the return value to be the absolute value or a relative value that might have a - (negative) sign if the passed in date is less than the current instance. This will default to true, return the absolute value.More here