Click here to Skip to main content
15,886,831 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If user inputs following data, I want to get free and Booked Locations
Start Date : 01/03/2015

End Date : 31/03/2015

Start Time : 02:30 PM

End Time : 05:30 PM

I have Following table structure for storing locations date wise

Date         Day          StartTime  EndTime   Location
2015-03-01   Sunday       2:30 PM    05:30 PM  Location - A
2015-03-02   Monday       4:30 PM    05:30 PM  Location - B
2015-03-03   Tuesday      5:45 PM    06:45 PM  Location - C


output like :

Location - A Booked

Location - B Booked

Location - C Free
Posted
Updated 30-Mar-15 22:12pm
v3
Comments
Afzaal Ahmad Zeeshan 31-Mar-15 4:13am    
You might consider using a database and third-party API to determine such values and then present them on the screen to the user. What do you have at the moment, just the idea?

1 solution

Start by changing your DB structure: Have a StartDate (DateTime), EndDate (DateTime), and a Location (which should probably be a foreign key into a different table).
At the moment, it looks like you are storing these as strings, which is a very poor idea as it makes comparison very, very difficult. You also don't need to store the day of the week as a column, and that can be worked out very easily from the date and can't be different for two identical dates!
This also allows for occasions when the booking starts on Sunday but ends on Monday morning at 1AM. That kind of thing is very awkward to cope with if you don't store end times as datetime values

Then you can start actually comparing your data. I can't give you an example as the question is too vague - there is no obvious reason from your data sample why "C" is free when "A" and "B" are booked.

So start by getting your data structures right, and then we can move on...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900