I have several dates in yyyy-mm-dd format and to manipulate them I am using the Carbon library.
My question is: How can I know if a random date was already in the current year?
For example today is 2018-10-19
, if I compare them with some dates, return the following:
$current = '2018-10-19';
$date1 = '2018-10-20'; return false
$date2 = '2018-11-21'; return false
$date3 = '2018-07-07'; return true
I have tried the following:
$current = Carbon::now();
$date_1 = Carbon::parse('2018-07-21');
if($current > $date_1)
{
echo 'The date was in the current year';
}
The problem I have is that I do not know how to apply this condition to find a date only in the current year, because if I compare the current date with a date of a previous year, it still returns true. How can I achieve this? Thank you