Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    date field error

    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())
    today=CDATE(today)
    set tp=cn.execute("select*from hit where affid="&affid&" AND
    datex=#"&today&"#")

    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
    today=Now()
    or
    today=Date()
    same error has occured...

    please help me.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Look here... Before you can use the Day() you have to have converted the date to a string. Heres a quick example:
    Code:
    today = Now()
    today = CDate(today)
    todaysDay =  Weekday(today)
    todaysMonth = Month(today)
    todaysYear = Year(today)
    
    Response.Write todaysDay & "." & todaysMonth & "." & todaysYear

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.
    Code:
    set tp=cn.execute("select*from hit where affid='" & affid & "' AND
    datex=#"&today&"#")

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    although each datatype is variant, the subtypes can matter, so CDate() does have a use

    dont just say other people are wrong mmkay

    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*)

  • #5
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.
    Code:
    <%
    Dim today, todaytoo
    today = Date()
    today = CDate(today)
    todaytoo = Date()
    If today = todaytoo then
    	Response.Write today & " = " & todaytoo
    Else
    	Response.Write "today <> todaytoo" 
    End if 
    %>
    Last edited by miranda; 01-25-2005 at 09:07 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •