ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 11th, 2003, 02:57 PM
madhouse madhouse is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 57 madhouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 16 m 49 sec
Reputation Power: 6
Delete Records Using A Date Field

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("act") = "clean" Then

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open ConnStr

strExpdt = cdate(Now())

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

conn.Execute sql

conn.close
set conn = nothing

strResponse = "All expired notices have successfully been deleted."

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??

Reply With Quote
  #2  
Old December 11th, 2003, 03:09 PM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 6
If you are using Access, I believe you must surround your inputted dates with pound signs. For SQL Server, they must be in single quotes. So I think you'd do something like this:

sql = "DELETE FROM tblNboard WHERE expdt < #" & Now() & "#"

Hope that helps.

Jill

Reply With Quote
  #3  
Old December 11th, 2003, 03:40 PM
madhouse madhouse is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 57 madhouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 16 m 49 sec
Reputation Power: 6
OK, I tried the following SQL statement:

sql = "DELETE * FROM tblNboard WHERE expdt < # " & Now() & " #"

and it deleted all the records in the table up the 12/11/2003...for some reason it doesn't delete the other records in the table up to todays date (11/12/2003)!!

Any ideas what is going on here??

Reply With Quote
  #4  
Old December 11th, 2003, 03:46 PM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 6
Oh, your dates are non-US dates then.
I was reading the date wrong, I guess.

Today's date US format is 12/11/2003
Where you are is 11/12/2003.

Perhaps you need to format the date differently in your expression...

Take a look here:

http://www.iisfaq.com/default.aspx?View=A284&P=119

Reply With Quote
  #5  
Old December 11th, 2003, 03:53 PM
madhouse madhouse is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 57 madhouse User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 16 m 49 sec
Reputation Power: 6
Sorry, I should have mentioned in my post that all dates are GMT (including the server date) and the locale I'm using is UK. So I don't see there being a problem with the date formats if everything is using GMT.

Reply With Quote
  #6  
Old December 11th, 2003, 04:02 PM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 6
It's still something with the dates...

Access should accept whatever the server locale/date setting is. Obviously that is working if your NOW() function returns the correct date.

Maybe try an input mask in Access? I'm not sure anymore. Sorry I'm no help.

J

Reply With Quote
  #7  
Old December 12th, 2003, 03:40 AM
srinath srinath is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Bangalore, India.
Posts: 21 srinath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to srinath
Hey,

The reason your SQL isnt deleting the records for the current date is because you are asking your SQL to delete the records < [ Less than ] current date. Try using <= with the SQL, it should help....

Regards

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Delete Records Using A Date Field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT