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 |
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2006-05-11 : 10:09:49
|
I want to code date >= (today - 30). How to code it? |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-11 : 10:11:34
|
[code]Where DateCol>=DateAdd(day, DateDiff(day,0,getdate()),-30) and DateCol<DateAdd(day, DateDiff(day,0,getdate()),1) [/code]MadhivananFailing to plan is Planning to fail |
|
|
kpmkrishnan
Starting Member
11 Posts |
Posted - 2006-05-11 : 10:12:39
|
Declare @Date datetimeset @Date = GetDate()select @Date-30 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-11 : 10:15:29
|
quote: Originally posted by kpmkrishnan Declare @Date datetimeset @Date = GetDate()select @Date-30
That wont give all the data requiredMadhivananFailing to plan is Planning to fail |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-11 : 20:54:47
|
quote: Originally posted by kpmkrishnan Declare @Date datetimeset @Date = GetDate()select @Date-30
getdate() will return date & time. so @date - 30 will gives you the date 30 days before today but not at 0 hour. So you might miss out some record that the date is 30 days before and time less than the current time.Example :select getdate(), getdate() - 30result :2006-05-12 08:52:24.640 2006-04-12 08:52:24.640 So you will missed out any record which date falls between 2006-04-12 00:00 to 8:52 KH |
|
|
|
|
|