Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > error '80040e07' wrong syntax in Date expression

Reply
Thread Tools

error '80040e07' wrong syntax in Date expression

 
 
Aloof
Guest
Posts: n/a
 
      06-29-2005
Using Access 2000
Windows Server 2003

The following code worked fine until we moved hosting companies

StartDate = Request.Form("StartDateMonth") & "/" & Request.Form
("StartDateDay") & "/" & Request.Form("StartDateYear")
EndDate = Request.Form("EndDateMonth") & "/" & Request.Form
("EndDateDay") & "/" & Request.Form("EndDateYear")

sql = "SELECT DISTINCT tblSessions.VisitorID FROM tblSessions WHERE
tblSessions.DateTimeEntrance Between #" & StartDate & " 0:0:1# And #" &
EndDate & " 23:59:59#;"

set RSVisitors = cn.execute("sql")

Response.write sql gives:

SELECT DISTINCT tblSessions.VisitorID FROM tblSessions WHERE
tblSessions.DateTimeEntrance Between #06/01/2005 0:0:1# And #06/31/2005
23:59:59#;

Now the same code gives an error message:


Microsoft JET Database Engine error '80040e07'

Syntax error in date in query expression 'tblSessions.DateTimeEntrance
Between #06/01/2005 0:0:1# And #06/31/2005 23:59:59#'.

/stats/stats_detail.asp, line 33

The old hosting company was Win2003, as is the new company. I've tried
changing the order of the date parts (YYYY/MM/DD, MM/DD/YYYY,
YYYY/DD/MM) but nonoe of the formats make a difference.

Any ideas?

TIA
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      06-29-2005
Aloof wrote:
> Using Access 2000
> Windows Server 2003
>
> The following code worked fine until we moved hosting companies
>
> StartDate = Request.Form("StartDateMonth") & "/" & Request.Form
> ("StartDateDay") & "/" & Request.Form("StartDateYear")
> EndDate = Request.Form("EndDateMonth") & "/" & Request.Form
> ("EndDateDay") & "/" & Request.Form("EndDateYear")
>
> sql = "SELECT DISTINCT tblSessions.VisitorID FROM tblSessions WHERE
> tblSessions.DateTimeEntrance Between #" & StartDate & " 0:0:1# And #"
> & EndDate & " 23:59:59#;"
>
> set RSVisitors = cn.execute("sql")
>
> Response.write sql gives:
>
> SELECT DISTINCT tblSessions.VisitorID FROM tblSessions WHERE
> tblSessions.DateTimeEntrance Between #06/01/2005 0:0:1# And
> #06/31/2005 23:59:59#;
>
> Now the same code gives an error message:
>
>
> Microsoft JET Database Engine error '80040e07'
>
> Syntax error in date in query expression 'tblSessions.DateTimeEntrance
> Between #06/01/2005 0:0:1# And #06/31/2005 23:59:59#'.
>
> /stats/stats_detail.asp, line 33
>
> The old hosting company was Win2003, as is the new company. I've
> tried changing the order of the date parts (YYYY/MM/DD, MM/DD/YYYY,
> YYYY/DD/MM) but nonoe of the formats make a difference.
>
> Any ideas?
>

The safest format to use is #YYYY-MM-DD hh:mm:ss# (note the hyphens), so if
you persist in using dynamic sql, that is the format you should use.

You would be better off using parameters, either via saved parameter
queries:
http://groups.google.com/groups?hl=e...TNGP11.phx.gbl

or using ODBC parameter markers in your sql string, and using a Command
object to pass the parameter values:
http://groups-beta.google.com/group/...e36562fee7804e

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
 
 
 
Paxton
Guest
Posts: n/a
 
      06-30-2005
Aloof wrote:
> Using Access 2000
> Windows Server 2003
>
> The following code worked fine until we moved hosting companies
>
> StartDate = Request.Form("StartDateMonth") & "/" & Request.Form
> ("StartDateDay") & "/" & Request.Form("StartDateYear")
> EndDate = Request.Form("EndDateMonth") & "/" & Request.Form
> ("EndDateDay") & "/" & Request.Form("EndDateYear")
>
> sql = "SELECT DISTINCT tblSessions.VisitorID FROM tblSessions WHERE
> tblSessions.DateTimeEntrance Between #" & StartDate & " 0:0:1# And #" &
> EndDate & " 23:59:59#;"
>
> set RSVisitors = cn.execute("sql")
>
> Response.write sql gives:
>
> SELECT DISTINCT tblSessions.VisitorID FROM tblSessions WHERE
> tblSessions.DateTimeEntrance Between #06/01/2005 0:0:1# And #06/31/2005
> 23:59:59#;
>
> Now the same code gives an error message:
>
>
> Microsoft JET Database Engine error '80040e07'
>
> Syntax error in date in query expression 'tblSessions.DateTimeEntrance
> Between #06/01/2005 0:0:1# And #06/31/2005 23:59:59#'.
>
> /stats/stats_detail.asp, line 33
>
> The old hosting company was Win2003, as is the new company. I've tried
> changing the order of the date parts (YYYY/MM/DD, MM/DD/YYYY,
> YYYY/DD/MM) but nonoe of the formats make a difference.
>
> Any ideas?
>
> TIA



In addition to Bob's reply, there is no 31st June. That's why your
expression doesn't evaluate. You need to test for/prevent invalid
dates being entered into your form.

Paxtonend

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
fatal error U1023: syntax error in expression while using NMAKE parveen.beniwal@rediffmail.com C++ 1 06-20-2007 05:28 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57