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 |
|
hong_ma
Starting Member
37 Posts |
Posted - 2006-02-28 : 14:19:59
|
| There are three fields ID(int), historyID(int), datatime(smallDate) in the report tableI would like to get data records which is before the datatime 60 days and after the datatime 30 daysfrom the report table.my query looks like thatselect ID, historyID, datatimefrom report where datatime between (datetime -60) and (datatime +30) Use DATEADD ( dd, 60, @datetime) to change (datetime -60) and (datatime +30) to change to smalldate typeis it right? Thanks |
|
|
JoeNak
Constraint Violating Yak Guru
292 Posts |
Posted - 2006-02-28 : 15:01:40
|
| I think you mean (not sure)WHERE datatime BETWEEN DATEADD(dd, -60, @datetime) AND DATEADD(dd, 30, @datetime)The smalldatetime datatype is just a smaller date range than datetime.If you're looking to strip the time off take a look here:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62354 |
 |
|
|
hong_ma
Starting Member
37 Posts |
Posted - 2006-02-28 : 15:24:24
|
| Sorry. I mean if my query can get all record which between that rang. in the another word. if I use WHERE datatime BETWEEN DATEADD(dd, -60, @datetime) AND DATEADD(dd, 30, @datetime).can I get all record during that rang? I am not sure. Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-28 : 15:26:57
|
| Why don't you try running it first?Tara Kizeraka tduggan |
 |
|
|
hong_ma
Starting Member
37 Posts |
Posted - 2006-02-28 : 15:46:47
|
| that's right. Thanks |
 |
|
|
|
|
|
|
|