Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dealense's avatar

Time Logic to code

Hello I am making booking website and I can't understand how can I check if time is clear, So I will explain what I do: when I choose service I send Date , Start Time, End Time and Time Between bookings so I need to check if that period for that day is clear.

Need Something Like this

whereRaw("? NOT BETWEEN quit_hour_start AND quit_hour_end", [$start, $end]

Sulution:

 if($chkStartTime > $startTime && $chkEndTime < $endTime)
            {
                $message = "chosen time is between in booked time";
            }
            elseif(($chkStartTime > $startTime && $chkStartTime < $endTime) || ($chkEndTime > $startTime && $chkEndTime < $endTime))
            {
                $message = "Start Time or End Time is between Booked Time";
            }
            elseif($chkStartTime==$startTime || $chkEndTime==$endTime)
            {
                $message = "Start Time or End Time is on the border of booked time";
            }
            elseif($startTime > $chkStartTime && $endTime < $chkEndTime)
            {
                $message = "Time is Already booked";
            }
0 likes
2 replies
s4muel's avatar
s4muel
Best Answer
Level 50

i suggest using this library: https://github.com/spatie/period

there is a $period->overlapsWith(Period $period): bool (and other period magic useful stuff)

it's not directly in eloquent, but i suppose you won't have any problems using it "outsude" to check if a period is clear

dealense's avatar

I checked and I liked functionality but there is a problem. For Some reason I can't import DateTimeImmutable, so I can't use that package.

Can you give me an example?

Please or to participate in this conversation.