For my code:
$today = Carbon::now()->toDateString();
$compare = Carbon::today()->toDateString() == '2020-12-03' ? 'yes' : 'no';
Log::debug('today '.$today);
Log::debug('compare '.$compare);
It return me:
2020-12-03
no
Anyone can help explain to me why it return 'no' instead of 'yes'.
Carbon::now()->toDateString() === Carbon::today()->toDateString()
So a better question is: was2020-12-03
the correct date in the default timezone you're running with PHP. Checkdate_default_timezone_get()
and if the date/time is what you expected in this timezone. My recommendation is to always set it to UTCdate_default_timezone_set('UTC')
and create specific object with user timezone dynamically it's the safest way.