Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:37:34+00:00 2026-06-14T23:37:34+00:00

Possible Duplicate: Determine Whether Two Date Ranges Overlap I am trying to work out

  • 0

Possible Duplicate:
Determine Whether Two Date Ranges Overlap

I am trying to work out if two time ranges in PHP overlap. I’ve been referring to Determine Whether Two Date Ranges Overlap for my initial try, however, it’s not matching all cases. If a time range is nested in between the start and end times of another time range, it’s not being matched. If it overlaps the beginning or the end of the shift, or if the shifts are exact matches, it works as expected.

Check out this image of what I’m talking about:

enter image description here

Basically, I am trying to hide any orange shifts if they overlap any red shifts anywhere. Here’s the relevant portion of code I’m trying to use to make this happen.

if(($red['start'] <= $orange['end']) && ($red['end'] >= $orange['start'])) {
    //Conflict handling
}

The values of the variables are UNIX timestamps. Working through the numbers logically, I understand why the statement above fails. There are obviously ways I could do more logic to determine if the one shift falls in the other shift (which is what I may need to do), but I was hoping for a more universal catch.

EDIT: Adding the values of each block’s start and end time. I agree what I have should work. The fact that it isn’t is where my issue lies. I’m probably overlooking something dumb.

orange-start = 1352899800
orange-end = 1352907000

red-start = 1352923200
red-end = 1352926200

Therefore my logic would state:

if((1352923200 <= 1352907000) && (1352926200 >= 1352899800))

So following that, the first comparison fails.

EDIT 2: It looks like my logic is sound (which I thought was the case), and my issue is something related to the UNIX timestamp not matching the actual time being displayed. I thank those who worked though this with me and help me discover that as being the issue. I wish I could accept both Andrey’s and Jason’s answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:37:35+00:00Added an answer on June 14, 2026 at 11:37 pm

    The logic is correct. The timestamps you provided for $red (8-8:50pm) and $orange (1:30-3:30pm) do not overlap.

    Given correct values (that reflect your screenshot), the overlap is indeed found:

    function show_date($value, $key) {
        echo $key, ': ', date('r', $value), PHP_EOL;
    }
    
    $red = array('start' => strtotime('today, 2pm'), 'end' => strtotime('today, 2:45pm'));
    $orange = array('start' => strtotime('today, 1:30pm'), 'end' => strtotime('today, 4pm'));
    
    array_walk($red, 'show_date');
    array_walk($orange, 'show_date');
    
    if (($red['start'] <= $orange['end']) && ($red['end'] >= $orange['start'])) {
        echo 'Conflict handling';
    }
    

    My guess would be you have a timezone conversion issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Which JRE I am using I'm trying to figure out whether the
Possible Duplicate: Determine if two rectangles overlap each other? Considering I have 2 squares
Possible Duplicate: Check if timestamp is x hours old? How do I determine whether
Possible Duplicate: how to determine location based on ip Is there a PHP function
Possible Duplicate: Determine whether client browser has java installed and can launch applets I
Possible Duplicate: MySQL: determine which database is selected? I'm trying to debug some problems
Possible Duplicate: How to determine whether a given Linux is 32 bit or 64
Possible Duplicate: How to determine the date one day prior to a given date
Possible Duplicate: Best way to determine if two path reference to same file in
Possible Duplicate: Detecting whether a PHP variable is a reference / referenced I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.