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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help on how to select 14 days in the past

Author  Topic 

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2009-02-20 : 15:54:38
Hi Group:

Need a little help selecting 14 days in the past. GETDATE (-14 DAYS)

HELP THANKS!!!!!!!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-20 : 15:58:24
WHERE SomeColumn >= GETDATE() - 14

Or you could use the DATEADD function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2009-02-20 : 15:59:40
Thank you tkizer :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-20 : 16:05:19
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-02-20 : 21:19:06
don't mention it



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-02-21 : 03:51:15
WHERE DATEDIFF(d,colname,getdate())<=14

Jai Krishna
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-21 : 04:01:26
quote:
Originally posted by Jai Krishna

WHERE DATEDIFF(d,colname,getdate())<=14

Jai Krishna


May not use the index if it is defined for date column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-21 : 08:42:31
DATEADD(day,-14,getdate())
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-22 : 02:09:17
"GETDATE() - 14" is equivalent to "DATEADD(day,-14,getdate())".

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2009-02-22 : 09:24:23
i would use something like:
where somedate >= cast(convert(varchar(11), getdate()-14, 121) as smalldatetime)
instead of only
where somedate >= getdate()-14

because the first one neglect the time, which is probably what you need, when you want to browse 14 days in past? if you use only getdate()-14 this take into consideration time (hours:minutes), and if you run second condition twice within a minute, you might get different results.
Go to Top of Page
   

- Advertisement -