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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:20:43+00:00 2026-05-23T08:20:43+00:00

First off, I marked this question as language agnostic, but I’m using PHP and

  • 0

First off, I marked this question as language agnostic, but I’m using PHP and MySQL. It shouldn’t affect the question itself very much tho.

I’m creating an application which shows times of certain shows throughout the week. Every single show is recurring (on weekly basis) and there might be shows which are airing through 2 days – eg. starting on Sunday at 23:30, ending on Monday at 00:30. I’m storing start of the show (day of the week – Monday, Tuesday… – it’s never exact date; time) and duration. There are never shows that would take more than 24 hours.

My problem is with validation if newly added shows aren’t overlapping some old ones. Especially if it comes to Sunday-Monday shows.

How are such recurring events usually handled on both DB side and server side?

tl;dr version with stuff I considered

My first idea was to create some custom validation algorithm, but it seemed too cumbersome and complicated. Not that I’d whine about complicated hand-made solutions, but I’m interested if there isn’t something more basic that I’m missing.

Other alternative that came to mind was to change table structure to use datetime (instead of “day of week” and “time”), and use a fake fixed date range to store the data. For example all Mondays would be set to 5th Jan 1970, Sundays would use 11th Jan 1970. There would be one exception to this rule – if there would be some show which starts on Sunday and ends on Monday, it would be stored as 12th Jan 1970. This solution would allow more flexible quering of the DB than the original one, and it would also simplify queries for shows which overlap between individual weeks (since we can do the comparison directly in the query). There are some disadvantages to this solution as well (for one, using fake dates might make it confusing).

Both solutions smell of wrong algorithms to me and would love to hear some opinions from more experienced fellow developers.

  • 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-23T08:20:44+00:00Added an answer on May 23, 2026 at 8:20 am

    Sounds like you could just store the starting minute of each show as an integer number of minutes since the start of the week (10,080 possible values).

    Then a show starting at minute $a with duration $dur_a will overlap $b if and only if

    (10080 + $b - $a) % 10080 < $dur_a

    For example consider a show starting at 11pm Sunday and another starting at 12.30am Monday. Here $a == 10020 and $dur_a == 120 and $b == 30. (10080 + $b - $a) % 10080 == 90. This is less than $dur_a and hence the shows overlap.

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

Sidebar

Related Questions

First off, this question is ripped out from this question. I did it because
First off, I know that this question begs the other question - should the
First off, I'm using Google AppEngine and Guice, but I suspect my problem is
This question is a spin-off/evolution of this question . (That question got marked as
First off - apologies if this or a similar question has been asked before.
First off, please accept my apologies if this question is basic, I mainly have
First off, I am using Windows XP. I have multiple hard drives and it
First off, there's a bit of background to this issue available on my blog:
First off: I'm using a rather obscure implementation of javascript embedded as a scripting
First off, I know next to nothing about language theory, and I barely know

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.