//flex table opened by JP

Click to See Complete Forum and Search --> : ASP dates


gnom
06-12-2005, 09:14 PM
I wrote an ASP script, which displays a form and then put taken data into a ACCESS database; one of it's field is 'date' of data/time type.
The problem occures bedause ASP script changes without no reason the date's format common for my Access database (yyyy-mm-dd) to some (mm/dd/yyyy) and moreover very often with a wrong values.
Part of my script, where all variables with letter f at the begining are fields of the form:

fdate = "'" & fyear & "-" & fmonth & "-" & fday & "'"
Response.write(fyear & "-" & fmonth & "-" & fday & "<br>")
Response.write(fdate & "<br>")
query = "INSERT INTO Game values (" & maxid & "," & date & "," & ftwith & "," & ftagainst & "," & fstadium & "," & ftype & "," & freferee & "," & fwithscore & "," & fagainstscore & ")
Response.write(query & "<br>")"
gives the output:
2003-12-12
'2003-12-12'
INSERT INTO Game values (9,6/12/2005,1,3,3,'friendly',4,1,8)

What is that 6/12/2005?? When I execute that query I get a new row but with year 1809!?! :confused:
I tried to put the date between ' characters (as is above) and without them....
Can anyone tell me what I'm dooing wrong?

ScaryBinary
06-12-2005, 09:57 PM
You have an error in your script.
query = "INSERT INTO Game values (" & maxid & "," & date & "," & ftwith & "," & ftagainst & "," & fstadium & "," & ftype & "," & freferee & "," & fwithscore & "," & fagainstscore & ")should bequery = "INSERT INTO Game values (" & maxid & "," & fdate & "," & ftwith & "," & ftagainst & "," & fstadium & "," & ftype & "," & freferee & "," & fwithscore & "," & fagainstscore & ")

"Date" is actually the VBScript (ASP) function for returning the current date, so if you name a variable "date", ASP is going to try go call the function "Date" instead. You had a coding error, so instead of inserting whatever was stored in your variable "fdate" your were storing whatever ASP determined the current date was.

ScaryBinary
06-13-2005, 12:25 AM
Originally posted by gnom
When I execute that query I get a new row but with year 1809!?! :confused:

It just dawned on me....I forgot you were using Access (ya, I know, you said it right in your post!). You have to surround dates with the pound sign "#" when you use dates in Access. Don't ask me why, it's one of those stupid Microsoft things. That's why your date is 1809 (must be the default date if you don't supply one). Your ASP should look like this:query = "INSERT INTO Game values (" & maxid & ",#" & fdate & "#," & ftwith & "," & ftagainst & "," & fstadium & "," & ftype & "," & freferee & "," & fwithscore & "," & fagainstscore & ")

gnom
06-13-2005, 03:50 AM
ha! what a stupid bug i made:D but how does it come that there is no massage from the interpreter, that I used unknown variable... btw 6/12/2005 is not a date, because brackets are not there - date(); Now I know why VBscript is so unpopular..
So the date in the query should look like this:
#2004-12-14#
or:
#' 2004-12-14'#

ScaryBinary
06-13-2005, 09:55 AM
Originally posted by gnom
ha! what a stupid bug i made:D but how does it come that there is no massage from the interpreter, that I used unknown variable... btw 6/12/2005 is not a date, because brackets are not there - date(); Now I know why VBscript is so unpopular..
So the date in the query should look like this:
#2004-12-14#
or:
#' 2004-12-14'#

You don't need the quotes.

VBScript, for some reason, will drop the parentheses for the function if it doesn't have any required arguments (at least that's my suspicion). Thus "Date()" is the same thing as "date". Since "date" is a function, you don't get any error messages since there is nothing invalid about that line of script.
Link to an Example from MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdate.asp)