Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/forums/asp/)
-   -   A problem with dates (http://www.go4expert.com/forums/dates-t4291/)

CaJack 13May2007 23:16

A problem with dates
 
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.

pradeep 14May2007 10:03

Re: A problem with dates
 
Try this,
Code: ASP.NET

Dim TodayTest As String = Today.ToString()
strSQL2 = "Update TestTBL SET DateStatus = '" & DateClosedString & "' WHERE EndDate >= '" & TodayTest  & "'"



All times are GMT +5.5. The time now is 01:20.