Link to home
Start Free TrialLog in
Avatar of gogetsome
gogetsomeFlag for United States of America

asked on

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 = ?
ASKER CERTIFIED SOLUTION
Avatar of aaronakin
aaronakin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kevin Cross
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()))