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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Select Dates From Database That Are of Certain Age?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am working on an application that looks at a database, and deletes records in tables that are 30+ days old. How do I do this?
 
Is this what you need?

<cfquery name=&quot;q1&quot; datasource=&quot;myDSN&quot;>
delete from tableName
where dateField1 < #createodbcdate(dateadd(&quot;d&quot;,-30,now()))#
</cfquery>

I believe this will work but do test on a duplicate table.

GJ
 
Dwayland,

If you are using SQL*Server you can insert records with a date column of the current day (in SQL*Server Getdate() function).

When you check what you want to delete Use the function DATEDIFF(day, insertdate, GETDATE()) to check if the result is greater then 30 in a having clause.

i.e.

DELETE TABLE
Having DATEDIFF(day, insertdate, GETDATE()) > 30


Hope this works for you




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top