in laravel 8 I need to check if $adItem->expire_date will end in next 3 days($fullcalendar_nearest_days) and making
$today = Carbon::today()->startOfDay();
\Log::info(varDump($adItem->expire_date, ' -00 $adItem->expire_date::'));
\Log::info(varDump($today, ' -1 $today::'));
$expireDateCheckNearest = $today->addDays($fullcalendar_nearest_days)->startOfDay();
\Log::info(varDump($expireDateCheckNearest, ' -1 $expireDateCheckNearest::'));
// 2021-06-30 2021-06-29 2021-07-02
$is_fullcalendar_nearest_days = $adItem->expire_date->between($today, $expireDateCheckNearest);
\Log::info(varDump($is_fullcalendar_nearest_days, ' -1 $is_fullcalendar_nearest_days::'));
I see logging output :
[2021-06-29 07:51:02] local.INFO: (Object of Illuminate\Support\Carbon) : -00 $adItem->expire_date:: : Array
(
[ * endOfTime] =>
[ * startOfTime] =>
[ * constructedObjectId] => 0000000029721fc40000000037698813
[ * localMonthsOverflow] =>
[ * localYearsOverflow] =>
[ * localStrictModeEnabled] =>
[ * localHumanDiffOptions] =>
[ * localToStringFormat] =>
[ * localSerializer] =>
[ * localMacros] =>
[ * localGenericMacros] =>
[ * localFormatFunction] =>
[ * localTranslator] =>
[ * dumpProperties] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)
[ * dumpLocale] =>
[date] => 2021-06-30 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Kiev
)
[2021-06-29 07:51:02] local.INFO: (Object of Carbon\Carbon) : -1 $today:: : Array
(
[ * endOfTime] =>
[ * startOfTime] =>
[ * constructedObjectId] => 0000000029721fc50000000037698813
[ * localMonthsOverflow] =>
[ * localYearsOverflow] =>
[ * localStrictModeEnabled] =>
[ * localHumanDiffOptions] =>
[ * localToStringFormat] =>
[ * localSerializer] =>
[ * localMacros] =>
[ * localGenericMacros] =>
[ * localFormatFunction] =>
[ * localTranslator] =>
[ * dumpProperties] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)
[ * dumpLocale] =>
[date] => 2021-06-29 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Kiev
)
[2021-06-29 07:51:02] local.INFO: (Object of Carbon\Carbon) : -1 $expireDateCheckNearest:: : Array
(
[ * endOfTime] =>
[ * startOfTime] =>
[ * constructedObjectId] => 0000000029721fc50000000037698813
[ * localMonthsOverflow] =>
[ * localYearsOverflow] =>
[ * localStrictModeEnabled] =>
[ * localHumanDiffOptions] =>
[ * localToStringFormat] =>
[ * localSerializer] =>
[ * localMacros] =>
[ * localGenericMacros] =>
[ * localFormatFunction] =>
[ * localTranslator] =>
[ * dumpProperties] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)
[ * dumpLocale] =>
[date] => 2021-07-02 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Kiev
)
[2021-06-29 07:51:02] local.INFO: scalar => (boolean) : -1 $is_fullcalendar_nearest_days:: :
I suppose that 2021-06-30 is between 2021-06-29 and 2021-07-02 and can not catch why $is_fullcalendar_nearest_days == false ?
Use addDays()
to add days:
Carbon::now()->addDays(3);
Also, it's always a good idea to add this to the query to fetch
->where('expire_date', '>', Carbon::now()->addDays(3))