We are trying to design a program that will allow users to book tutors based on tutors' availability. So we want tutors to tell us when (what time, day, etc) they are available/not available, and when a user books a specific day and time, we only want to show that user the tutors that are available for that particular day and time.
For example, tutors could tell us they are available M-W from 9-5PM.
How could I design such a table?
I was thinking of doing the followin
non-availability:
(this allows tutors to tell me they are not available on a specific date ... say 4/15/2012 10PM)
date date
time_start datetime
time_end datetime
recurring_non-availability
(this allows tutors to tell me that they are not available every Monday from 9-5pm)
dayOfWeek enum
time_start
time_end
So basically, tutors can specify for each day of the week, the times they are not available. They can also specify specific dates they are not available. If a user wants a tutor for a specific date like 4/20 10AM, I will first query the non-availability table to make sure there are no conflicts for 4/20 10 AM, and then query the recurring_non_availability table to make sure they are no conflicts for Friday (4/20 is on a Friday) 10 AM. I am not sure if this design will give me the best picture of a tutor's availability.
Perhaps set up a table with all the days of the week tutors will be available and then have the times they are stored within like so?
Tutor monday tuesday wednesday thursday friday
bob 9-5 9-5 9-5 10-3 9-12
Related
I've been looking for a solution here in the community, but I have not found anything specific. I need to do searches for birthdays among a period using only the month and month day (excluding year). I have users with their birthdays registered in date fields in my MySQL.
Name | Dt. Birth
Julian | 1990/01/18
Luiz | 2000/02/15
Morgana | 1973/02/01
I need to realize two different tasks.
1st - Let's suppose today date is February 01. How could I take today's date and decrease 14 days, searching for users whose birthday was on previous 2 weeks? (only Julian would be listed).
Another query will list users whose birthday is today (only Morgana would be listed).
And a third one should list the birthdays within next two weeks (only Luiz would be listed)
I was using these code, but they don't seem to work at all times.
select * from user where DAYOFYEAR(dateBirth) between DAYOFYEAR(CURDATE())-14 and DAYOFYEAR(CURDATE())-1;
select * from user where DAYOFYEAR(dateBirth) = DAYOFYEAR(CURDATE());
select * from user where DAYOFYEAR(dateBirth) between DAYOFYEAR(CURDATE())+1 and DAYOFYEAR(CURDATE())+14;
2nd - In a form, I will select two days and months |01||January ||15||February|and the users whose birthday is within this range will be listed. (All users listed)
Maybe this fiddle help you visualize the question. http://www.sqlfiddle.com/#!9/1dec7a/5
I reproduce the above queries that show some inaccuracy. If you change values (-14/+14 and (-1/+1), you shall be able to list the users.
I'm making a web app in PHP that calculates vacations and some are fixed, say for example, Christmas, so instead of adding dates like
2015-12-25
2016-12-25
2017-12-25
2018-12-25
Is there any way to add something like
*-12-25
That accounts for every 25th of December of ALL the years? I know PHP has this but since I'm getting the dates from a Vacation Dates table that is populated by the admin I can't figure out how to do this in PHP, else I'll have to default to add 10 years to each entered date
I have a problem that I just cannot seem to get my head around, and hope someone can help give me some advice.
Ever since getting solar PV cells fitted on my house roof, I have been generating electricity and in accordance to some (rather generous) incentives to do this kind of thing, have been making money for every kWh of electricity I generate. Seeing this as being a bit of a database project, I set about writing some PHP/MySQL to track daily generation, and now have nearly a year's worth of daily kWh readings, which are nicely presented to me in graphical form, both in a month-by-month view, and as a yearly (grouped into months) graph.
I'm now wanting to expand the system to show revenue in monetary terms, rather than kWh of electricity. Currently, the figure is £0.454 per kWh, though this figure changes every year on the April 1st (it was £0.433 previously).
This is my current MySQL structure:
Table feedin:
year (year4) rate (float)
2010 0.433
2011 0.433
2012 0.454
Table generation:
day (DATE) reading (float)
2011-12-01 7.682
2011-12-02 5.747
2011-12-03 4.982
... ...
2012-08-13 8.022
2012-08-14 19.449
2012-08-15 5.484
My first attempt at this was all rather cumbersome with a very mixed mess of PHP and MySQL queries, with the bulk of the logic being done in PHP (my MySQL skills are "limited", at best). However, as time is going on, I see that it would be ideal if the whole thing were done in MySQL.
I've no real idea how to tackle this. My initial thoughts are that we need to select yearly chunks of data (well, date-ranges from April 1st in one year, to March 31st the next), and multiply it by the appropriate year rate. And that "appropriate year rate is the rate applicable at the start of that date range, ie, as of April 1st).
Ideally, I'd like the query to be able to cope with multiple yearly boundaries, so, for example, several years down the road, I'd like to be able to query the absolute total revenue produced to date. Ultimately, I would just like to pass the query the start and end dates, and it returns the correct figure.
Link the year of the generation date to the year of the feedin tariff
SELECT *, generation.reading*feedin.rate AS profit
FROM generation, feedin
WHERE YEAR(generation.day)=feedin.year
BUT as this must relate to year start of APRIL 1st
SELECT *, generation.reading*feedin.rate AS profit
FROM generation, feedin
WHERE YEAR(DATE_SUB(generation.day, INTERVAL 3 MONTH))=feedin.year
This will move the recorded dates back 3 months too, making them Jan-Dec instead of Apr-Mar wich will then match the feedin year
something along these lines:
select year, sum(reading) as total_generation, (total_generation*feedin.rate)
FROM feedin
LEFT JOIN generation on feedin.year = YEAR(generation.day)
GROUP BY year
Hope this does what you want (tested and working)
SELECT (a.rate*b.reading),a.year as amount from generation as b, feedin as a where Year(b.day)=a.year
TLDR: Need to understand the best way for a user to be able to add a date(s) & time(s) for an event, and how to structure database
Explanation:
When a user adds an event, they need to be able to choose the date of the event, whether or not it will repeat daily/weekly/monthly, start and end time of the event or "all-day", if it's weekdays only or weekend...etc. Basically everything you can do w/ Google calendar when you create an event and they need to be able to edit it too (if that matters). But ALSO, they need to be able to add another date/time - for instance:
Add an event where on Monday and Wednesday of this week and three weeks from now, it goes from 8-10pm. On Tuesday and Thursday this week only, it goes from 6-9pm.
My thoughts so far:
Create a "dates" table with a HABTM relationship w/ my "events" table. When a user adds a date (with all the options of repeat..etc etc., it runs a function to process those repeats/limits...etc and adds all the dates into the dates table w/ their start/end times.
But - then how do I manage it if they want to edit that - since it just created multiple fields.
Question / Help?:
Am I even on the right track with this? I'm new to CakePHP, and it's hard for me to wrap my head around the best ways to do things... I'm not yet looking for technical help (would not turn it down though) - for now, I just need to get the idea for the best way to structure everything to be able to manage this. Maybe I need a "dates" table AND a "times" table? Maybe a "dates" table with an id that references many individual rows in a "dates_data" table?
Thank you very much ahead of time for any help / direction!
You're doing great. Let me just share my thoughts.
If I would design this, I'd have 3 models:
Event
id
user_id
description
created (datetime)
updated (datetime)
Schedule
id
event_id
description
start (datetime)
end (datetime)
duration (time, if empty(NULL) it means this is a whole day event)
repeat_time (e.g. 3:00pm means 3pm daily)
repeat_day (for weekly/monthly, e.g. Monday, Monday & Tuesday, Monday to Friday)
repeat_date (for monthly, e.g. 1 means every 1st day of month, 31 means every 31st or end of the month)
repeat_anniversary (for specific date every year, e.g. every December 25th)
Date
id
schedule_id
start (datetime)
end (datetime)
Now let's have an example of an event. Let's say we want an event that will repeat every Saturday and Sunday of May & June 2011 at 1:00pm until 3:00pm (two hours):
The events table contains the basic detail of an event. One record will be saved here.
The schedules table is separated so that you could add multiple schedules. One record will also be saved in schedule with the following fields:
duration: 02:00
start: 2011-05-01
end: 2011-06-30
repeat_time: 13:00:00
repeat_day: 01,07 (Sunday & Saturday)
Now on dates table, there will be 17 records, one for each occurrence of the schedule. The reason why I separated this is that it will be easier for me know when will the event fall. This will be useful, for example, when creating the calendar. One of the records for the dates table will look like this:
start: 2011-05-01 13:00:00
end: 2011-05-01 15:00:00
Now what if the user edits the schedule? The schedule record would be edited. All dates record would also be edited. You don't wanna delete and recreate the dates, since you might use each record for another model (e.g. user might want to tag other users as attendees for each date of the event).
I hope this helps. Goodluck on your project!
I'm building a home rental system. The system stores profiles of homes and users can book homes for rent for periods as between one day to a year. I've got the booking part all set up except I am faced with a requirement from teh client to be able to set certain dates and date ranges as un bookable for homes.
A home can be available for a whole year for rent, or can be available for 6 months, or be unavailable on discreet days eg: Holidays and weekends for summer homes etc.
I'm perplexed as how would I be able to set up a database table to store this information considering that the information must be retrievable by a sql query. I mean consider the following situation, a home can be rented through out the year except on wednesdays, the 4th of July, 10 November to 25th December and 31st December.
How do I store this in a database and be able to run a query to check for a homes availability between set dates. I'm wokring in php MySql
There are two different concepts that you're describing: the "on Wednesdays" is not as much of a date range as it is a recurrence pattern. The same goes for "weekends".
You're probably looking at two different tables in addition to your property table that define these unavailable dates: one that represents specific date ranges and one that represents recurrence patterns.
Property
|
-------------- ---------------
| |
PropertyUnavailableRecurrence PropertyUnavailableRange
(Bear in mind that you might want to figure out shorter names)
PropertyUnavailableRecurrence would need to store the information necessary for turning "Wednesdays" and "weekends" into viable decision logic. I can't model this for you, since all of you've presented in this pattern are specific days of the week, but I'd imagine that you'd need to be able to account for "First of the month" or "Second Wednesday of the month", but I don't know. In any case, this is where you'd need to store that information.
PropertyUnavailableRange would just contain simple From and To dates that define the range. This part is pretty simple.
Of course, an alternative would be to take the recurrence patterns specified in the application and turn them into discreet PropertyUnavailableRange records, but you'd still need to set up a table to store these recurrences and associate the discreet records with a recurrence so that you could manage them.
One approach is to have a table, PropertyUnavailable, with the following structure:
create table PropertyUnavailable
(
property_id number not null,
when date not null
);
This table would have a row for each day that the property is not available because of a black out period (e.g., every Wednesday, Holiday, etc). I am ignoring how you will store the meta information of the pattern -- all this table wants are rows for each day where the property is not available because of a blackout period.
I assume you will also have a table for reservation days, PropertyReserved, with the same structure as above plus a foreign key to reservation_id (or something similar).
Now to see what day's are unavailable/reserved for a given date range, the sql would be something like this:
SELECT a.when, 'blackout'
FROM PropertyUnavailable a
WHERE a.when between <from_date> to <to_date>
UNION ALL (
SELECT b.when, 'reserved'
FROM PropertyReserved b
WHERE b.when between <from_date> to <to_date>
);
If nothing is returned with the query, then the property is available between the date range specified (from_date, to_date).
Did you consider simply booking those "unbookable" dates in the name of the system?
It appears that you are not clear about what is required to be stored in teh database; and what is required in code segments. Set the "unbookable" dates aside for a moment, assume you only have actual booked dates. Catcall has a point. What does your current code look like, when you search for available dates ?
SQL is quite capable of handling dates and performing date arithmetic. My NonSQL is not, you will have to store more in the databse than in real SQL. But you do not need to store rows per date. The Reservation table needs FromDate and ToDate only.