in reply to Date/Time Parse with time exemptions and SQL querying
I think you have two real issues here -- how to store the data in the back end, and how to present it to the user so it's editable.
It's really going to be a function of what your user interface is -- you mentioned Excel, but then said it wasn't, and you also mentioned it's in a SQL table. I would assume that you'd use a 'date' field, so it's just a matter of dealing with the rest of it.
I'd treat the time ranges as reoccuring events, and look into how various other databases handle these things (Palm's storage of weekly occuring events, iCalendar specification, etc.), so that I'd be likely to be compatable ... how you present that to the user, I have no idea, without knowing your user interface.
As for gathering data, I assume you just want to query for time that matches a range -- I'm not sure if all date functions are consistent across databases, but the general logic of 'M-F 7am-8pm' is:
SELECT * FROM tablename WHERE appid = 'application id' AND DAYOFWEEK(datefield) IN ( 2,3,4,5,6 ) AND HOUR(datefield) BETWEEN 7 and 19The above assumes that items exactly at 8pm aren't of interest, and that 'BETWEEN' in your database includes the endpoints. (ie, 7 is 'between' 7 to 19). If you want to deal with minutes or include the end time , you can't use the 'between' trick, and will have to compare if the hours and minutes of the day fall in the right period, which you can simplify by using fractional hours:
SELECT * FROM tablename WHERE appid = 'application id' AND DAYOFWEEK(datefield) IN ( 2,3,4,5,6 ) AND (HOUR(datefield)+MINUTE(datefield)/60) BETWEEN 7 and 20The logic should be good, but you might need to hammer out syntax issues for your particular DB (the date processing functions (name, how it handles days of the week), and if between is inclusive or exclusive)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Date/Time Parse with time exemptions and SQL querying
by guice (Scribe) on Sep 02, 2005 at 18:28 UTC |