[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

help with datedif

Hello, I need to delete a row if the datecreated is greater than 30 days.

Declare @Today as datetime set @Today = GetDate()
Delete Friends
where dateCreated = ?
0
gogetsome
Asked:
gogetsome
1 Solution
 
aaronakinCommented:
I assume you mean, if the datecreated value is more than 30 days in the past?  If so...

WHERE DateCreated < DATEADD(DAY,-30,GETDATE())
0
 
Kevin CrossChief Technology OfficerCommented:
Aaron is correct.  If you have timestamps and want to ensure that you don't get different results based on time you run query do this to force date to midnight.

DELETE Friends
WHERE DateCreated < DATEADD(DAY, -30, DATEDIFF(DAY, 0, GETDATE()))
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now