View Full Version : date field error
01-22-2005, 02:32 PM
hello everyone ,
i have a problem for two days and i havent just resolved it.
there is my asp codes :
today=Day(Now()) & "." & Month(Now()) & "." & Year(Now())
set tp=cn.execute("select*from hit where affid="&affid&" AND
affid field is as text and datex fields is as "date/time" . my database is ms access 2000.
an error has occured when run above codes.
i code as
same error has occured...
please help me.
01-22-2005, 07:34 PM
Look here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctcdate.asp)... Before you can use the Day() you have to have converted the date to a string. Heres a quick example:
today = Now()
today = CDate(today)
todaysDay = Weekday(today)
todaysMonth = Month(today)
todaysYear = Year(today)
Response.Write todaysDay & "." & todaysMonth & "." & todaysYear
01-22-2005, 09:49 PM
ASP 3.0 using VBScript does not have any variable typing. All variables are of the type variant. So you do not need to use CDate.
Your problem lies in that you are missing the single quotes around the variable affid. it is of the text datatype, so must be enclosed in single quotes. If it were a number datatype then you wouldn't use the single quotes. So change your statement to look like this and run it.
set tp=cn.execute("select*from hit where affid='" & affid & "' AND
01-25-2005, 01:41 PM
although each datatype is variant, the subtypes can matter, so CDate() does have a use
dont just say other people are wrong mmkay :thumbsup:
im gunna go make a function that returns the date and time in the specified common format (such as "h:mm tt" could be 2:47 PM, or "HH:mm:ss" could be 14:47:32 when a date is sent (as a date subdatatype btw *pokes tongue out*).. you never know, might be useful if vbLongDate etc dont cover it (which they dont usually ^_^).. unless ofcourse there is a builtin way of doing this....*looks around.. watches the tumbleweed blow past*)
01-25-2005, 09:30 PM
I didn't say it didnt have a use, just that in ASP 3.0 it isnt needed. But the problem was not in the date but was in the sql statement trying to insert a variable into a text datatype just like you would a number datatype. You have to use single quotes around text datatypes, and that is what the datatype in the database was.
Using CDate to convert to the type Date isn't needed because if you run this code you will see that they are the same thing.
Dim today, todaytoo
today = Date()
today = CDate(today)
todaytoo = Date()
If today = todaytoo then
Response.Write today & " = " & todaytoo
Response.Write "today <> todaytoo"
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.