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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-03-08 : 08:54:00
|
| Brian writes "So I am using the between statement in following query, but I need to return today's date as well as all dates between today and 14 days from now. here is query:SELECT id,eventTitle, eventDesc, eventstDate FROM tblEvent WHERE (eventstDate BETWEEN GETDATE() AND DATEADD(day, 14, GETDATE()) and restid=186any help is greatly appreciated" |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2006-03-08 : 09:09:30
|
I'm assuming the problem is that the dates are stored with a time of midnight. I.e. today's date: 2006-03-08 00:00:00.000 will not fall into a range with a lower bound returned by the GETDATE() function at this point in time (2006-03-08 14:03:27.017). There's a few different ways of handling this. I usually use a combination of DATEDIFF and DATEADD to get the number of days between a fixed date ('1900-01-01' which can be reprented as zero) and today's date and then add that difference to the fixed date:DECLARE @Today DATETIME SET @Today = DATEADD(day, 0, DATEDIFF(day, 0, GETDATE())) Replace GETDATE() in your code with this variableMark |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-08 : 09:39:23
|
| Where datecol>=DateAdd(day,Datediff(day,0,getdate(),0) and datecol<DateAdd(day,Datediff(day,0,getdate(),15)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|