In this tutorial I will show you two days to check if a given date is today’s date in Laravel. These 2 methods are isToday method and isSameDay method of Carbon library class in Laravel.
First Method: Using IsToday()
In the first method, we will use the IsToday() method.
This is how you can do it in code:
use Carbon\Carbon;
$date = Carbon::parse('2023-08-25');
if ($date->isToday()) {
echo "It is Today"
} else {
echo "It is not Today"
}Second Method: Using isSameDay()
In this second method, we can use the isSameDay() method which is also available in the Carbon Library.
Here is how you do it in the code:
use Carbon\Carbon;
$date = Carbon::parse('2023-08-25');
if ($date->isSameDay(Carbon::now())) {
echo "It is Today"
} else {
echo "It is not Today"
}Conclusion
In the article example, we have covered 2 different ways to check if a Date is Today’s Date in Laravel.
Read also: Laravel Carbon addMinutes() | Laravel Carbon Add Or Subtract Minutes and Hours Examples