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

Karthik_hebbar's avatar

Checking if a timeslot(eg: 10:00 - 14:00) comes between another timeslot like (9:30 - 15:00)

Hi All,

I have requirement where i should check if a given timeslot (eg: 10:00 - 14:00 ) comes between another timeslot (eg: 9:30 - 15:00), i have been stuck with this a for a week now, not able to figure out, if anyone could help me to figure this out

Eg: 'yes' if exist b/w timeslot and 'no' otherwise. existing timeslot (9:30 - 13:00)

  • 10:30 - 11:30 - yes
  • 10:30 - 15:00 yes
  • 13:00 - 19:00 no

thanks.

0 likes
1 reply
Snapey's avatar

You have a collision

if new start is between existing start and existing end

OR new end is between existing start and existing end

OR ( new start is before existing start AND new end is after existing end)

you have to account for the new period starting or ending between the existing times, or completely encapsulating it

Please or to participate in this conversation.