Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Ferox
Starting Member
18 Posts |
Posted - 2005-10-19 : 04:36:54
|
| Hi guys! I’m making a schedule–type application and I’ve got a table of events with a ‘start time’ and ‘end time’ (both datetime fields.) I’m trying to list the event that is currently on at the moment, but I’m having trouble pulling out the correct record. This is an example of the data:ID Event Start End1 Opening 09:00 10:302 Discussion 10:30 12:003 Lunch 12:00 12:354 Discussion 12:35 14:005 Questions 14:00 15:006 Break 15:00 15:30EtcI’m trying to pull out the current active event, but sometimes it comes out wrong (at the end of the hour etc) How should I go about grabbing this record? Should I be using datediff someway?Any help would be greatly appreciated! :) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-19 : 04:54:45
|
| What is your expected result?MadhivananFailing to plan is Planning to fail |
 |
|
|
Ferox
Starting Member
18 Posts |
Posted - 2005-10-19 : 05:00:33
|
| I plan to pull out the current event at the top (based on getdate()) and then the events after that below:e.g. based on time now = 10:48am2 Discussion 10:30 12:00 - CURRENT EVENT3 Lunch 12:00 12:354 Discussion 12:35 14:005 Questions 14:00 15:006 Break 15:00 15:30 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-19 : 05:23:09
|
| If Start and End columns are DateTime, then how do you store only Time part?Try thisSelect Columns from yourTable where GetDate() between Start and EndMadhivananFailing to plan is Planning to fail |
 |
|
|
Ferox
Starting Member
18 Posts |
Posted - 2005-10-19 : 06:19:31
|
| Thanks madhivanan that BETWEEN functionality worked brilliantly!My datetime fields are actually stored as '01/01/1900 12:00:00' etc but I only ever use the time element. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-19 : 06:24:14
|
Well. Whenever you post questions post full value and dont truncate value MadhivananFailing to plan is Planning to fail |
 |
|
|
Ferox
Starting Member
18 Posts |
Posted - 2005-10-19 : 06:29:11
|
| Ok sorry about that...and many thanks again! :) |
 |
|
|
|
|
|