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!

Comparing dates in a WHERE clause

Status
Not open for further replies.

precimonito

Programmer
Jan 20, 2001
18
EC
Here's my problem:
Using an ASP page, I recover a recordset and one of the fields I get is a date. I store that date in a variable and then when I try to run an update clause using that date in the where, the update never runs.
temp = 0
val1 = objrecordset.fields("col1")
val3 = objrecordset.fields("col3") 'this is the date
strSQL = "UPDATE TABLE1 SET col2 = 200 where (col1 = "
strSQL = strSQL & val1 & " AND col3 = '" & val3 & "');"
objconnection.execute strSQL, temp
col2 doesn't get to be 200 and temp is still 0
I don't know if I'm comparing the date in the wrong way
When I show val3 on my page, the date is fine so that's not the problem. If I run the clause only using col1 in the WHERE, I have no problem and the update gets done, so the problem is just when I want to compare the date.
 
Make sure that your date value (var3)is in American date format (mm-dd-yyyy)

SQL*Server expects an american date format and not the european (dd-mm-yyyy).
 
You can also convert tha date in the format you need:
" AND col3 = CONVERT(datetime,'" & val3 & "',103)"
where 103 means that the date is in the format "dd/mm/yyyy" for more informations about che parameters of the CONVERT function see Books OnLine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top