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

  • Home
  • SEARCH
  • 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 8527741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:38:29+00:00 2026-06-11T08:38:29+00:00

I have a database containing events. Every event has a timestamp. The events are

  • 0

I have a database containing events. Every event has a timestamp. The events are evenly spread trough the day, but every night there is a timespan without data. My problem is that the night is not well defined. It can be from 23pm to 7am next day, or from 2am to 10am the same day or even only from 8pm to 23pm the same day.

Now I want to calculate the intervall of the events, but without the big timespan without events. But I have no idea how to find this timespan. My problem is, that there can be days without timespan, or two days with the same timespan (for example 8pm to to midnight of the first day, midnight to 7 am of the second day).

My question is now: How to find this timespan?

I would prefer a solution in MySql only, but if it is not possible it would be possible to use PHP, too.

  • 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-11T08:38:30+00:00Added an answer on June 11, 2026 at 8:38 am

    How about self-joining a table to the following row, then doing a time-diff between the joined tables, and finding the maximum diff?

    Assuming your schema is something like this (and assuming entries are in time order):

    CREATE TABLE log (
      id INT NOT NULL AUTO_INCREMENT,
      occurred_at DATETIME,
      event VARCHAR(255),
      PRIMARY KEY (id),
      INDEX (occurred_at)
    );
    

    Something like this:

    SELECT 
      TIMEDIFF(after.occurred_at, before.occurred_at) AS time_gap,
      `before`.*, 
      `after`.*
    FROM 
      log `before` JOIN 
      log `after` ON after.id = before.id+1 
    ORDER BY time_gap DESC LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database containing two tables: event and session (one event has multiple
I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').
I have a database containing addresses, one address per Row. Contains every address in
I have a database containing records collected every 0.1 seconds, and I need to
I have a database containing users and roles. The table Users has a reference
Hay, i have a database holding events. There are 2 fields 'start' and 'end',
I have a database containing user details. I don't have separate columns for 'firstname'
I have a database containing a single huge table. At the moment a query
I have a database containing a list of status updates and time stamp. by
Say I have a database containing Books and Users and these users have certain

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.