Level 51
$days = $days == 0 ? 1 : $days;
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Dear artisan, I am building a room booking system, I need to calculate days based on check in and check out days. The following code returns 0 if user chooses the same day. How can I round up to 1 ?
$check_in = Carbon::parse($request->check_in); // '2022-12-12'
$check_out = Carbon::parse($request->check_out); // '2022-12-12'
$days = $check_out->diffInDays($check_in); // 0
$days = $days == 0 ? 1 : $days;
Please or to participate in this conversation.