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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:50:15+00:00 2026-06-16T09:50:15+00:00

I try to create an application for the iPhone where you can set appointments.

  • 0

I try to create an application for the iPhone where you can set appointments. Everything is saved into a MySQL database and I currently get the data through JSON into my app. This is a workflow:

  • User1 defines when he is working. E.g. 8am – 4pm.
  • User2 wants to have an appointment with user1, e.g. 8am-9am.

The script should be able to do this:

  • the appointment is within the user’s work hours; and
  • it does not clash with an existing appointment, which can happen in three possible ways:
    • the clashing appointment starts during the new appointment; and/or
    • the clashing appointment ends during the new appointment; or
    • the clashing appointment starts before and ends after the new appointment.

These are the important tables:

// new row should be added here when the conditions above are met
create table ios_appointment (
   appointmentid int not null auto_increment,
   start timestamp,
   end timestamp,
   user_id_fk int
)

// a working hour has a n:1 relationshipt to ios_worker
create table ios_workinghours (
   workinghoursid int not null auto_increment,
   start timestamp,
   end timestamp,
   worker_id_fk int
)

// employee, has a 1:n relationship to ios_workinghours
create table ios_worker (
   workerid int not null auto_increment,
   prename varchar(255),
   lastname varchar(255),
   ...
)

The input for the select clause are two timestamps, start and end. These are defined by the user. So the script should check if user 2 is working at that specific time and if there are already appointments.

I currently have something like this, but that uses the user_id to link the tables:

SELECT EXISTS (
  SELECT *
  FROM   ios_appointments a JOIN ios_workhours h USING (user_id)
  WHERE  user_id = 1
     AND h.start <= '08:00:00' AND h.end >= '09:00:00'
     AND (
               a.start BETWEEN '08:00:00'  AND  '09:00:00'
           OR  a.end   BETWEEN '08:00:00'  AND  '09:00:00'
           OR (a.start < '08:00:00' AND a.end > '09:00:00')
         )
  LIMIT  1
)

Every help is appreciated. Thx.

  • 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-16T09:50:16+00:00Added an answer on June 16, 2026 at 9:50 am

    You either need to have your app read in the data and determine if the time is available OR you need to create a view that has the available “time slots” (e.g. every 30 minutes).

    Here’s how I would do it:

    CREATE TABLE #timeslot
    (
    timeslot_id INT PRIMARY KEY IDENTITY(1,1),
    timeslot_time DATETIME NOT NULL
    )
    
    DECLARE @startime DATETIME, @endtime DATETIME
    SELECT @starttime = '12/25/2012 08:00:00.000', @endtime = '12/25/2012 15:00:00.000'
    
    WHILE @starttime < @endtime BEGIN
       INSERT INTO #timeslot (timeslot_time)
        VALUES (@starttime)
        SET @starttime = DATEADD(mm,30,@starttime)
    END
    
    SELECT
       w.workerid,
       ts.timeslot_time
    INTO
       ios_workertimeslot
    FROM
       #timeslot ts
    FULL OUTER JOIN
       ios_worker w
       ON  (1 = 1)
    
    
    SELECT
       wts.workerid,
       wts.timeslot_time,
       ap.appointmentid,
       CASE WHEN ap.appointmentid IS NOT NULL THEN 0 ELSE 1 END AS AvailableSlot
    FROM
       ios_workertimeslot wts
    JOIN
       ios_workinghours wh
       ON  (wts.workerid = wh.workerid)
       AND (wts.timeslot_time >= wh.start)
       AND (wts.timeslot_time < wh.end)
    LEFT JOIN
       ios_appointment ap
       ON  (wts.workerid = ap.workerid)
       AND (wts.timeslot_time >= ap.start)
       AND (wts.timeslot_time < ap.end)
    

    This will leave you with a data set that indicates the available and non-available timeslots.

    Hope this helps!

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

Sidebar

Related Questions

I try to create an application for the iPhone where you can set appointments.
I try to create some li elements in my XUL Application. Theres only the
I need to create an application for the iPhone that will connect to a
I am making a small iPhone application in which I have implemented the database
I am attempting to create a 3 tab iPhone Application with UITableViews on 2
I'm having a weird experience. I create any type of iPhone application, add a
I create a brand new Single View Application iPhone app in Xcode 4.2, it
I try create a map for open ~/.vimrc, but open the ~/.vimrc only when
I want to try create something like Zend's Server Pagecache. What I want to
I try to create donate via PayPal button and add custom select with amount.

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.