1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A problem with dates

Discussion in 'ASP' started by CaJack, May 13, 2007.

  1. CaJack

    CaJack New Member

    Joined:
    Mar 21, 2007
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    I keep getting an error when I run my code. Here’s the error “The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
    The statement has been terminated”. It points to this part of my code…
    Code:
     cmd.ExecuteNonQuery() 
    Here’s my code…
    Code:
        Private Sub TestDate()
            Dim DateClosedString As String = "Closed"
            Dim cnn As Data.SqlClient.SqlConnection
            Dim cmd As Data.SqlClient.SqlCommand
            Dim TodayTest As Date = Today
            Dim strSQL2 As String
    
            strSQL2 = "Update TestTBL SET DateStatus = '" & DateClosedString & "' WHERE EndDate >= '" & Today & "'"
            Dim conn As String
            conn = "Data Source=.\SQLEXPRESS;AttachDbFilename=""|DataDirectory|\aspnetdb.mdf"";Integrated Security=True;User Instance=True"
            cnn = New Data.SqlClient.SqlConnection(conn)
            cmd = New Data.SqlClient.SqlCommand(strSQL2, cnn)
            cnn.Open()
            cmd.ExecuteNonQuery()
            cnn.Close()
    End Sub 
    What I want it to do is check my TestTBL and if any EndDates are greater or equal to todays date, write closed to the DateStatus field.
    The dates are saved to the database as DateTime. This is copy and passed from an enddate field in my database “22/05/2007 00:00:00”. I’m not really need the time part but I cant find any other way.
    Can anyone help? I’ve been pulling my hair out over this one for days.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Try this,
    Code:
    Dim TodayTest As String = Today.ToString()
    strSQL2 = "Update TestTBL SET DateStatus = '" & DateClosedString & "' WHERE EndDate >= '" & TodayTest  & "'"
    
     

Share This Page