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 |
|
JohnJohn73
Yak Posting Veteran
57 Posts |
Posted - 2007-10-25 : 18:00:55
|
| I created a report based on the dates 10/22/07 and 10/25/07. However, the results were not complete when cross referenced on paper. I realized that by using the c# DateTime.Now function, I was actually querying with 10/22/07 4:34 PM and 10/25/07 4:34 PM. So I was losing results that happened before 4:34 PM on 10/22. I can easily fix this situation in code by going new DateTime(yy,mm,dd,0,0,0) to get the whole day for 10/22/07, but how would I go about doing it in SQL? This would prevent me from making mass changes to my program code.Thanks for any help. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-25 : 18:11:13
|
| [code]WHERE yourColumn >= DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0) AND yourColumn < DATEADD(Day, DATEDIFF(Day, 0, GetDate())+1, 0)[/code]First part gets today's date with 00:00 as time, second part gets tomorrow's date with 00:00. You get the entire day by doing yourColumn >= today's date and yourColumn < tomorrow's date.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
JohnJohn73
Yak Posting Veteran
57 Posts |
Posted - 2007-10-25 : 18:15:58
|
| Thanks again for your help. You always bring manna to the masses! |
 |
|
|
|
|
|
|
|