Comparing a date field to a date in a form.

L

Les Juby

"SELECT id, title FROM Businesses WHERE Date_Added >= " &
Request.Form("Since_Date")

This SQL string returns all records from the table Businesses and does
not seem to be able to recognise Request.Form("Since_Date") as a valid
date. The Since_Date value is entered into a form field as
"01-Jan-2005" and appears to be treated as a date; when viewing the
SQL statement(with a response.write) it shows the date as 1/1/2005
even if it is entered into the form as 2005/1/1

I've also tried CDate(Request.Form("Since_Date")) with no luck,
although this was the treatment that worked when the SQL statement was
running in an .idc file.

Date_Added is a regular DateTime field in an Access 2000 database

Any suggestions please ?????

.les.
 
M

McKirahan

Les Juby said:
"SELECT id, title FROM Businesses WHERE Date_Added >= " &
Request.Form("Since_Date")

This SQL string returns all records from the table Businesses and does
not seem to be able to recognise Request.Form("Since_Date") as a valid
date. The Since_Date value is entered into a form field as
"01-Jan-2005" and appears to be treated as a date; when viewing the
SQL statement(with a response.write) it shows the date as 1/1/2005
even if it is entered into the form as 2005/1/1

I've also tried CDate(Request.Form("Since_Date")) with no luck,
although this was the treatment that worked when the SQL statement was
running in an .idc file.

Date_Added is a regular DateTime field in an Access 2000 database

Any suggestions please ?????

.les.

Try:

SELECT id, title
FROM Businesses
WHERE Date_Added >= #" Request.Form("Since_Date") & "#"
 
R

Rob Meade

...
Date_Added is a regular DateTime field in an Access 2000 database

Any suggestions please ?????

Hi Les,

Try reformatting the date before using it..for example:

dtmSinceDate = Request.Form("Since_Date")

dtmSinceDate = Year(dtmSinceDate) & "-" & Month(dtmSinceDate) & "-" &
Day(dtmSinceDate)

SQL = "SELECT id, title FROM Businesses WHERE Date_Added >= " & dtmSinceDate


Regards

Rob
 
B

Bob Barrows [MVP]

Les said:
"SELECT id, title FROM Businesses WHERE Date_Added >= " &
Request.Form("Since_Date")

This SQL string returns all records from the table Businesses and does
not seem to be able to recognise Request.Form("Since_Date") as a valid
date. The Since_Date value is entered into a form field as
"01-Jan-2005" and appears to be treated as a date; when viewing the
SQL statement(with a response.write) it shows the date as 1/1/2005
even if it is entered into the form as 2005/1/1

I've also tried CDate(Request.Form("Since_Date")) with no luck,
although this was the treatment that worked when the SQL statement was
running in an .idc file.

Date_Added is a regular DateTime field in an Access 2000 database

Any suggestions please ?????

.les.

Stop using dynamic sql. Use parameters.

sSQL="SELECT id, title FROM Businesses WHERE Date_Added >= ?"
arParms = array(cdate(Request.Form("Since_Date")))
set cmd=createobject("adodb.command")
set cmd.ActiveConnection = cn
set rs=cmd.execute(,arParms,1)

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top