• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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