Hi all,

I have the following VB.NET code where I am attempting to connect to a SQL Server table, query it to find out if a date in the table is between a derived date called "fileCreateDate" and now/today.

Sub getDateModified()

    Dim fileCreatedDate As DateTime = File.GetCreationTime(strFilePath + "\CPI1.csv")
    Dim stmt As String
    Dim dtRd As String

    SQLConn.ConnectionString = ConnString
    stmt = "select Release_Date from dbo.tblRelease_Dates where Release_Date Between '" + fileCreatedDate + "' And 'CAST(GetDate() AS DATE)'"
    SQLCmd.Connection = SQLConn
    SQLCmd.CommandText = stmt
    SQLdr2 = SQLCmd.ExecuteReader
    If SQLdr2.HasRows Then
        While SQLdr2.Read()
            dtRd = SQLdr2.GetString(0)
        End While
    End If

End Sub

However, the code stops with an error at SQLdr2 = SQLCmd.ExecuteReader. I'm sure the error is because of 'CAST(GetDate() AS DATE)' in the string stmt but I am unsure as to how to fix this so that the query is between fileCreateDate and today. The value being returned from fileCreateDate is 9/4/2012 10:58:03 AM and there is a date between that and now that I need. Can someone see what I am doing wrong?

Recommended Answers

glad to hear. and good job posting the update so that others with a similar problem can benefit.

Jump to Post

All 3 Replies

I solved this, it was a simple mistake:

stmt = "select Release_Date From tblRelease_Dates Where (Release_Date Between '" + fileCreatedDate + "' And GETDATE())

glad to hear. and good job posting the update so that others with a similar problem can benefit.

Thanks JorgeM, It bothers me on another forum that I moderate when OP come on, ask a question, and then never return again. I know that when that happens it is most likely because they have figured things out either on their own or from a different forum. I totally believe in forum etiquette and courtesy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.