Jump to content

Date booking percentages - Help required with logic


Recommended Posts

I'm trying to write a statistics page for a small booking system I am writing and need a bit of help with the logic (which will also be helpful when I'm scripting the front end to it).

My table has the following notable fields:
[0]start_date (date)
[0]start_slot (enum)
[0]end_date (date)
[0]end_slot (enum)

Each day is to have 3 slots, a morning (0), afternoon (1) and evening (2). I'm trying to work out the percentage of booked slots for each week of a selected year.

I have written the script that works out the date which each of the 52 weeks of the year start on, but I'm having troubles figuring out the logic behind working out how many slots have been booked when looping through the days of each week.

Any ideas?

Many thanks.
  • 2 weeks later...
I'd say: find the number of taken slots on a specific day, for a specific slot.

Try:

[code]
SELECT COUNT(*) FROM Table WHERE
  start_date >= $date AND end_date <= $date #only count entries within date range
AND (
  IF($date = start_date, #if the date is a bookings start date,
      IF($slot >= start_slot, TRUE, FALSE), #...count entry if start_slot is equal or bigger than the one we're looking for
  IF($date = end_date, #if the date is a bookings end date,
      IF($slot <= end_slot, TRUE, FALSE), #...count entry if start_slot is equal or smaller than the one we're looking for
  TRUE) #otherwise just count it
)
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.