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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:27:29+00:00 2026-05-15T21:27:29+00:00

Env: mysql How should I go about modeling the event duration for the following

  • 0

Env: mysql

How should I go about modeling the event duration for the following scenarios…

Today is Monday (start of the week)

  1. One day event scheduled between 10 AM – 5 PM today.
  2. Every day event open from 10 AM – 11 AM from today till 1 week. (inclusive of weekends)
  3. Every day event open from 10 AM – 11 AM from today till 2 weeks. (exclusive of weekends)
  • 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-15T21:27:30+00:00Added an answer on May 15, 2026 at 9:27 pm

    I would choose the easy way:

    CREATE TABLE `scheduler` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `startDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      `endDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `weekendIncluded` tinyint(4) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    

    EDIT:

    In the light of recent comments, a solution that would also support recurrent events and a more fine-grained time interval selection would be:

    CREATE TABLE `events` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(255) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
    

    This table holds all the event information (i.e. name, …).

    CREATE TABLE `scheduler` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `event_id` int(11) unsigned DEFAULT NULL,
      `isRecurrent` tinyint(4) DEFAULT '0',
      `startDate` date DEFAULT NULL,
      `endDate` date DEFAULT NULL,
      `startTime` time DEFAULT NULL,
      `endTime` time DEFAULT NULL,
      `onMonday` tinyint(4) NOT NULL DEFAULT '0',
      `onTuesday` tinyint(4) NOT NULL DEFAULT '0',
      `onThursday` tinyint(4) NOT NULL DEFAULT '0',
      `onWednesday` tinyint(4) NOT NULL DEFAULT '0',
      `onFriday` tinyint(4) NOT NULL DEFAULT '0',
      `onSaturday` tinyint(4) NOT NULL DEFAULT '0',
      `onSunday` tinyint(4) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`),
      KEY `FK_scheduler` (`event_id`),
      CONSTRAINT `events_scheduler` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED;
    

    These are the corresponding time intervals for each of the events. For recurrent events we will set the isRecurrent field to True.

    For this data set

    insert into `events` (`id`,`name`) values (1,'@work');
    insert into `events` (`id`,`name`) values (2,'This Friday\'s Movie');
    insert into `events` (`id`,`name`) values (3,'Fishing on Sunday');
    insert into `events` (`id`,`name`) values (4,'Get a Haircut');
    insert into `scheduler` (`id`,`event_id`,`isRecurrent`,`startDate`,`endDate`,`startTime`,`endTime`,`onMonday`,`onTuesday`,`onThursday`,`onWednesday`,`onFriday`,`onSaturday`,`onSunday`) values (1,1,1,NULL,NULL,'09:00:00','18:00:00',1,1,1,1,1,0,0);
    insert into `scheduler` (`id`,`event_id`,`isRecurrent`,`startDate`,`endDate`,`startTime`,`endTime`,`onMonday`,`onTuesday`,`onThursday`,`onWednesday`,`onFriday`,`onSaturday`,`onSunday`) values (2,2,0,'2010-07-29','2010-07-29','20:00:00','23:00:00',0,0,0,0,0,0,0);
    insert into `scheduler` (`id`,`event_id`,`isRecurrent`,`startDate`,`endDate`,`startTime`,`endTime`,`onMonday`,`onTuesday`,`onThursday`,`onWednesday`,`onFriday`,`onSaturday`,`onSunday`) values (3,3,0,'2010-08-01','2010-08-01','04:00:00','14:00:00',0,0,0,0,0,0,0);
    

    this (pretty much contrived) query

    SELECT  MAKE_SET(SCHED.onMonday | SCHED.onTuesday * 2 | SCHED.onThursday * 4 | SCHED.onWednesday * 8 | SCHED.onFriday * 16 | SCHED.onSaturday * 32 | SCHED.onSunday * 64,"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") AS days,
            EVT.name,
            CONCAT(IFNULL(SCHED.startDate,""), " ", IFNULL(SCHED.startTime,"")) AS startTime, CONCAT(IFNULL(SCHED.endDate,""), " ", IFNULL(SCHED.endTime,"")) AS endTime FROM events EVT
    INNER JOIN scheduler SCHED ON SCHED.event_id = EVT.id
    WHERE SCHED.isRecurrent
    
    UNION ALL
    
    SELECT  "ONE-TIME" AS days, EVT.name, CONCAT(SCHED.startDate, " ", SCHED.startTime) AS startTime, CONCAT(SCHED.endDate, " ", SCHED.endTime) AS endTime FROM events EVT
    INNER JOIN scheduler SCHED ON SCHED.event_id = EVT.id
    WHERE NOT SCHED.isRecurrent;
    

    lists all the events:

    Mon,Tue,Wed,Thu,Fri   @work                  09:00:00             18:00:00
    ONE-TIME              This Friday's Movie    2010-07-29 20:00:00  2010-07-29 23:00:00
    ONE-TIME              Fishing on Sunday      2010-08-01 04:00:00  2010-08-01 14:00:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following test fails: #!/usr/bin/env python def f(*args): >>> t = 1, -1 >>>
Env: JPA 1, Hibernate 3.3.x, MySQL 5.x We auto generate database schema using hbm2ddl
I tried for about 3-4 hours trying to get the mysql gem to install
I need to query a Mysql database with Python. I have virtual env installed
I have the following code: $body = <SOAP-ENV:Envelope>.$data.</SOAP-ENV:Envelope>; $ch = curl_init($FD_Add); curl_setopt($ch, CURLOPT_POST, 1);
Env.: Vista SP1, SQL Server Express 2005 I'm able to connect to my localhost
Env.: VS 2008, .NET 2.0, WinForms I have a listview in Tile mode. Some
We are developing an extension (in C# .NET env.) for a GIS application, which
It´s really a hard job figuring out how to get MySQL and mysql gem
Firstly, I should say I'm completely new to Pylons, trying to learn web development

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.