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

Delete Records Using A Date Field

Status
Not open for further replies.

madhouse

Programmer
Sep 17, 2002
165
GB
I've got a table with three fields:

ref (Autonumber)
notice (memo)
expdt (Date)

I'm trying to use an SQL statement to delete all records where expdt < the current date (Now). Here is the code I'm using:

<%
If Request.Querystring(&quot;act&quot;) = &quot;clean&quot; Then

Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open ConnStr

strExpdt = cdate(Now())

sql = &quot;DELETE FROM tblNboard WHERE expdt < &quot; & Now()

conn.Execute sql

conn.close
set conn = nothing

strResponse = &quot;All expired notices have successfully been deleted.&quot;

End If
%>


However, this just gives me the following error:

Syntax error (missing operator) in query expression 'expdt < 11/12/2003 19:54:25'.

What am I doing wrong??
 
Well I've just double checked this and it works

strDate=year(date) & &quot;/&quot; & month(date) & &quot;/&quot; & day(date)
sql=&quot;delete from table1 where dater<#&quot; & strdate & &quot;#&quot;
conn.execute sql

 
Thanks everyone for your help, but to make life a little easier I'm going to add the value of the &quot;validfor&quot; field into the table as well. Then I can subtract &quot;expdt&quot; from Now() and if it's greater than &quot;validfor&quot; delete the record. Just seems an easier way than having to change the LCID or working out how to use an SQL statement!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top