| Author |
Topic |
|
Coolpics22
Starting Member
5 Posts |
Posted - 2009-11-03 : 14:09:47
|
| I have an column in my table called EndDate and I need only the data with an end date after the current date to be displayed. How can this be done?Another part to that is I would like the data to only be displayed before a certain time of day, say 5.00pm.Does anyone have any ideas??Thanks |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-11-03 : 14:28:27
|
| So does the endDate have to before 5PM? Or do you want to display only if the current time is before 5 PM?WHERE endDate > getdate() and datepart(hour,getdate()) < 17JimEveryday I learn something that somebody else already knew |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-03 : 14:31:59
|
[ sniped]CREATE TABLE x (Col1 int IDENTITY(1,1) PRIMARY KEY, EndDate datetime)GOCREATE INDEX xEndDate ON x (EndDate)GOINSERT INTO x (EndDate)SELECT '1/1/2010 4:00PM' UNION ALLSELECT '2/1/2010 9:00PM' UNION ALLSELECT '3/1/2009 4:00PM' UNION ALLSELECT '4/1/2009 4:00PM' UNION ALLSELECT '5/1/2009 4:00PM' UNION ALLSELECT '6/1/2009 4:00PM' UNION ALLSELECT '7/1/2009 4:00PM' UNION ALLSELECT '8/1/2009 4:00PM' UNION ALLSELECT '9/1/2009 4:00PM' UNION ALLSELECT '10/1/2009 4:00PM' UNION ALLSELECT '11/1/2009 4:00PM' UNION ALLSELECT '12/1/2009 4:00PM' GOSELECT *, DATEPART(hh,EndDate) FROM xWHERE EndDate > GetDate() AND DATEPART(hh,EndDate) < 17GODROP TABLE xGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-03 : 14:34:50
|
quote: Originally posted by jimf So does the endDate have to before 5PM? Or do you want to display only if the current time is before 5 PM?WHERE endDate > getdate() and datepart(hour,getdate()) < 17JimEveryday I learn something that somebody else already knew
I think the row's time has to be lees than 5:00PM, not the current datetimeBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
Coolpics22
Starting Member
5 Posts |
Posted - 2009-11-03 : 14:47:05
|
| Wow, thanks for the quick response! The data in my endDate column is formatted something like this, 11/02/2009 12:00:00 AM; automatically putting in the 12.00.00 AM for time. Is this formatted right? Because I have tried using getdate() but for some reason I am not getting the results I need.The endDate wouldnt need to be before 5pm but I think that is how I would want it instead displaying it only if current time is before 5.Thanks so far! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Coolpics22
Starting Member
5 Posts |
Posted - 2009-11-03 : 15:35:06
|
| Actually my endDate column is datetime, I just had an asp calendarextendar that was putting my selected end date as 11/02/2009 12:00:00 AM instad of how I have it now as 02/11/2009 12:00:00 AM. But after making that change it works.If I wanted to get only the data with an end date after AND on the current date should it not work to useWHERE EndDate >= GetDate() AND DATEPART(hh,EndDate) < 17sorry for not specifying this in initial post. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Coolpics22
Starting Member
5 Posts |
Posted - 2009-11-03 : 16:02:46
|
| I would like the day to count up to 5. but if it counts up until midnight then that is ok. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Coolpics22
Starting Member
5 Posts |
Posted - 2009-11-03 : 18:16:07
|
| Thanks alot for all the help! It is working. :) |
 |
|
|
|