Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding 7 days to a date

Status
Not open for further replies.

h3lpm3

Technical User
Jan 31, 2007
1
0
0
GB
I am trying to remove data from a table in a database. Like a sort of archiving processes whereby I remove one week of data at a time.

So I select the min date from the table (select min (TIMESTAMP) from <tblname>)

Which returns a date in the following format -> 20070114 13:22:59.843671 +0000?

I want to be able to add seven days to that field so I will end up with 20070121

And then I can delete from table name where TIMESTAMP < '20070121'

Any suggestions?

Thanks

Anjel
 
You want your where to look something like this.
Code:
where TIMESTAMP < (SELECT dateadd(wk, 1, convert(datetime, min(TimeStamp), 101)) from table)

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top