In this tutorial, we will be discussing how you can check if a Date is Today’s Date in laravel by two different methods. We will be using isToday
method and isSameDay
method.
Let’s get started!
Table of Contents
First Method: Using IsToday()
So in this first method, we will be using IsToday()
method which is present in the Carbon Library.
Here is how you do it in the controller or view:
use Carbon\Carbon;
$date = Carbon::parse('2023-01-24');
if ($date->isToday()) {
echo "yes, its today date"
} else {
echo "no, its not today date"
}
Second Method: Using isSameDay()
In this second method, we will be using isSameDay()
method which is again present in the Carbon Library.
Here is how you do it in the controller or view:
use Carbon\Carbon;
$date = Carbon::parse('2023-01-24');
if ($date->isSameDay(Carbon::now())) {
echo "yes, its today date"
} else {
echo "no, its not today date"
}
Conclusion
In the article above, we have covered 2 different ways of checking if a Date is Today’s Date in laravel. See you in the next one 🙂
Write a Reply or Comment