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 6936819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:17:00+00:00 2026-05-27T12:17:00+00:00

Okay, so I have a start datetime and an end datetime for multiple items.

  • 0

Okay, so I have a start datetime and an end datetime for multiple items. I need to find out if there are more than 3 items that are within the same datetime as each other. I just can’t wrap my head around this one, I can get the days of each individual item into an array using this function

function getDatesBetween2Dates($startTime, $endTime) {
$day = 86400;
$format = 'm/d/y g:i A';
$startTime = strtotime($startTime);
$endTime = strtotime($endTime);
$numDays = round(($endTime - $startTime) / $day) + 1;
$days = array();
for ($i = 0; $i < $numDays; $i++) {
    $days[] = date($format, ($startTime + ($i * $day)));
}
return $days;
}

The problem is, it only get the first time and just adds a full day to every day afterward. it doesn’t take into account for the last days time. I just can’t think of an efficient way to do this.

Just to clarify, let me give you an example. I have 5 items in my table, they each have a datetime range.. start and end. I need to check if 4 or more of those items have any days in their date range that are the same. Can anyone point me in the right direction? Thanks.

  • 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-05-27T12:17:01+00:00Added an answer on May 27, 2026 at 12:17 pm

    Change for ($i = 0; $i < $numDays; $i++) { to for ($i = 0; $i <= $numDays; $i++) { to get all dates in the range, including the last date.

    Unfortunately you’re going about this the wrong way. Here’s some pseudocode of how I would do it:

    Iterate through the list of date ranges
        Log the earliest start date
        Log the last end date
    
    Iterate through all dates between the earliest start date and the last end date
        Iterate through the list of date ranges, to determine how many date ranges contain the current date
            If more than three date ranges contain the current date, then store it in an array of conflicting dates
    

    I don’t believe this is the most efficient way, but unless you’re dealing with huge date ranges or quite a large number of dates, it will be relatively fast.

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

Sidebar

Related Questions

Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay so on my homepage http://www.stat-me.com i have a link that when pressed activates
Okay, I have an app that tells me what color of pixel I touched
Okay so I'm struggling more than I should with this. I've been to the
Okay, so I have this array. Currently it pulls multiple payment amounts and dates
Okay, so I have an assignment to code (using Java,but I don't think that
Okay, start out saying this is hard to explain with words only. So i
Okay let me start off by saying I have been looking around a lot
Okay I have this RewriteRule which is supposed to redirect any request for the
Okay I have a series of objects based on a base class which are

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.