# Finding if time overlaps

**URL:** <https://forum.kirupa.com/t/finding-if-time-overlaps/301181>\
**Category:** programming\
**Created:** [December 4, 2009, 5:05pm UTC](https://forum.kirupa.com/t/finding-if-time-overlaps/301181 "2009-12-04T17:05:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imagined](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@imagined](https://forum.kirupa.com/u/imagined)\
**Post date:** [December 4, 2009, 5:05pm UTC](https://forum.kirupa.com/t/finding-if-time-overlaps/301181/1 "2009-12-04T17:05:20Z")

</div>

I’m trying to create a function to find out if two time ranges overlap.

function($from, $to, $day, $from\_compare, $to\_compare, $day\_compare)

$from, $to, $from\_compare, $to\_compare should get a 24-hour time format, for example, 13:00-17:00

$day and $day\_compare would contain something like Monday or Tuesday, but not a specific date.

I’ve been googling it but can’t find a good solution. Any suggestions? I’m working with 24-hour format. Also, the function needs to take into account the following scenario: 18:00-02:00 (6pm-2am)?

Any suggestions would be appreciated
