How I compare Date in MS Access database versus Date in SQL Server database?

NewComer

Active member
Joined
Jan 2, 2010
Messages
34
Programming Experience
Beginner
I have to compare and take the different days between the date in MS Access database (DateList) versus the date in VB:

Dim Date_Out As DateTime
Dim Day_Different As Integer

strSQL = "SELECT * FROM DateList WHERE Date_In < #" & Date_Out & "# "

da = New OleDbDataAdapter(strSQL, dbConn)
dt = New DataTable
da.Fill(dt)

If dt.Rows.Count() > 0 Then
'Debug error
Day_Different = Date_Out - dt.Rows(0).Item("Date_In")
End If


*) If I take Date_Out.day and CDate(dt.Rows(0).Item("Date_In")).day ... it might produce error as Day_Out = 2011-06-01 and dt.Rows(0).Item("Date_In") = 2011-05-31 equals - 30 days instead of 1 day. That doesn't including different more than 1 month


Thank you any help
 
Parameter in query:
VB.NET:
strSQL = "SELECT * FROM DateList WHERE Date_In < ?"
Parameter in command object:
VB.NET:
da.SelectCommand.Parameters.AddWithValue("date", Date_Out)
probably:
VB.NET:
Day_Different = (Date_Out - CDate(dt.Rows(0)("Date_In"))).Days
 
I found the solution that to use:

Dim SpanDays As TimeSpan

SpanDays = dateOut - CDate(dt.Rows(0).Item("Date_In"))
Day_Different = CInt(SpanDays.Days)

Thank for trying to help
 
TimeSpan.Days property is already type Integer so CInt is not necessary.
 
Back
Top