July 8, 2004 at 3:44 am
Hi All,
I want to complete a simple delete where datestamp is older than 60 day's..
Any ideas? Im new at SQL Server.. Sorry if this is a pants question.
Thanks
Adam
July 8, 2004 at 5:02 am
DELETE FROM table1 WHERE CONVERT(VARCHAR(10), Field1, 101) <
SELECT DATEADD(DAY, -60, CONVERT(VARCHAR(10), GETDATE(), 101))
is one way. There are multiple other ways of doing this too.
Good Hunting!
AJ Ahrens
webmaster@kritter.net
July 8, 2004 at 2:54 pm
DELETE FROM MyTable WHERE MyDateTimeField <= DATEADD(dd, -60, GETDATE())
July 9, 2004 at 6:28 am
If you don't have to worry about the time when the statement is ran (if this is run at 11:20am, it will delete everything older than 60 days ago at 11:20am) you can use:
delete from TABLE where DATEFIELD < getdate() - 60
However, if you want to delete everything before the start of the day (60 days ago), you could use:
delete from TABLE where DATEFIELD < convert(varchar, getdate() - 60, 101)
Hope this helps.
Jarret
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply