I have the following code working in Laravel 8 (which uses Carbon by default) with PHP7.
$carbon = new Carbon();
$test1 = 1;
$test2 = 1;
if ($carbon > '1970-01-01 00:00:00') {
$test1 = 2;
}
if ($carbon > '2030-01-01 00:00:00') {
$test2 = 2;
}
# ends with $test1===2 and $test2===1
The problem is that when I searched this usage I found many posts indicating they had to something much more complicated.
However all those posts are about 3-4 years old. Is this a newly supported feature of Carbon or my working code was just pure luck and there are cases not working?
EDIT:
I found in the greaterThan function implementation that even they are using raw string in the example for their compare-target date. This seems so weird considering all the content of other online posts.
/**
* Determines if the instance is greater (after) than another
*
* @example
* ```
* Carbon::parse('2018-07-25 12:45:16')->greaterThan('2018-07-25 12:45:15'); // true
* Carbon::parse('2018-07-25 12:45:16')->greaterThan('2018-07-25 12:45:16'); // false
* Carbon::parse('2018-07-25 12:45:16')->greaterThan('2018-07-25 12:45:17'); // false
* ```
*
* @param \Carbon\Carbon|\DateTimeInterface|mixed $date
*
* @return bool
*/
public function greaterThan($date): bool
{
return $this > $date;
}