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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:10:00+00:00 2026-05-28T19:10:00+00:00

I have an application where a person is allowed to set alarm for particular

  • 0

I have an application where a person is allowed to set alarm for particular events for particular time and days. For eg:-
there are two events- A & B and these events occur repeatedly on certain days of the week schedule of these events go like:

EVENT A – occurs every SUNDAY,MONDAY and WEDNESDAY at 7am and 9pm.
EVENT B – occurs every SUNDAY and TUESDAY at 6am and 8pm.
EVENT C – occurs every MONDAY,WEDNESDAY and THURSDAY at 8am,9pm.

The user is shown a form where he can select the days and enter the timings which are same for all the days selected.He can create as many events as he wants.

In the DB as of now I have created 7 columns for each of the days and one column for the timings. I know I might be making it unnecesarily complicated. The above data is represented as

EventNAME SUN MON TUE WED THU FRI SAT Timings
 A         1  1    0   1  0    0   0   7,21
 B         1  0    1   0  0    0   0   6,20
 C         0  1    0   1  1    0   0   8,21

Now for some reason I have to find the next nearest day and time when an event occurs For eg: if today is wednesday morning 6am , I have to get the next nearest event as event a -morning 7 am. and at wednesday morning 8 am, I have to get the next nearest event as event C at morning 8 am.

How do I get the next nearest day and time from such a schema? Is there a better way of designing the table?

  • 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-28T19:10:01+00:00Added an answer on May 28, 2026 at 7:10 pm

    I’d use a second table with two colums: (event_id, next_run_time)

    Whenever you add an event to the schedule table, calculate the next time it should fire. Build a function for that. The logic would be:

    • See if the task needs to run today (today’s column is 1, and one of the timings is in the future)
    • If not, look for the next day it should trigger, first timing.

    Then figuring out what needs to be run is a simple matter of (pseudo-sql):

    select (for update) event_id from next_run_times where next_run_time < now
    

    And whenever you trigger the task, update its next run time using the same function you built earlier.

    Careful: you’ll need some form of locking to prevent a task from being run twice if to “scheduler”s run at the same time.

    I’m not sure whether having a column for each day of the week is useful, unless you want to query specifically for “jobs scheduled on Wednesdays” for instance. A more compact format (like a plain string with 0101100 for your last task for instance) could be more practical depending on your programming language and exact query needs. (Or possibly redesign that table with (event_id, day_number, timing) (singular “timing”), selection of the “next runtime” would be easier.)

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

Sidebar

Related Questions

So I have a XNA application set up. The camera is in first person
I have a ASP.NET application I've inherited from the person who did my job
I have a model in my rails application which is class Person < ActiveRecord::Base
I have application where i have two view controllers my first view and second
I have an application that uses a nested set model class to organise my
I have an application that uses a nested set model class to organise my
I have an application that uses Python appengine, there is a service that updates
I have an application that animates a person traversing the halls of a spaceship.
I have already asked a question regarding a simple fault-tolerant soft real-time web application
I have a Facebook application that is inside IFRAME. When person opens application the

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.