There is a fair chance that the database is trying to interpret the literal date strings in en-US format. You can eliminate that problem entirely by using parameters in the query, like this:
Dim oledbSql = "SELECT * FROM myTable WHERE recDateTime BETWEEN ? AND ?"
Dim oledbSqlCmd As New OleDbCommand(oledbSql, oledbConn)
Dim dtStart As New DateTime(2013, 12, 30, 23, 49, 9)
Dim dtEnd As New DateTime(2013, 12, 31, 0, 1, 29)
oledbSqlCmd.Parameters.Add(New OleDbParameter With {.ParameterName = "@Start", .OleDbType = OleDbType.Date, .Value = dtStart})
oledbSqlCmd.Parameters.Add(New OleDbParameter With {.ParameterName = "@End", .OleDbType = OleDbType.Date, .Value = dtEnd})
' now execute the query
You don't actually have to name the parameters, but it makes it easier to see what is happening (which aids maintainability). You do, however, have to add them in the order in which they are used as a ?
is used as a placeholder for each parameter.
If you are using SQL Server as the database, it is better (because it is optimised for it) to use System.Data.SqlClient rather than System.Data.OleDb, and you can then use named parameters in the query:
Dim sql = "SELECT * FROM myTable WHERE recDateTime BETWEEN @Start AND @End"
Dim sqlCmd As New SqlCommand(sql, sqlConn)
Dim dtStart As New DateTime(2013, 12, 30, 23, 49, 9)
Dim dtEnd As New DateTime(2013, 12, 31, 0, 1, 29)
sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@Start", .SqlDbType = SqlDbType.DateTime, .Value = dtStart})
sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@End", .SqlDbType = SqlDbType.DateTime, .Value = dtEnd})
' now execute the query
Please don't ever be tempted to use .AddWithValue
as it will make assumptions about the data type which will foul things up unexpectedly.
Also, you should (almost) always explicitly state the columns you want from the database instead of using *
because the database is free to return the columns in any order it wants to - which may not be the order you think they will be returned in.
Depending on the actual database you are using, parameter names might need to have something like a :
instead of an @
as a prefix.
[I thought I might as well answer the question rather than only be negative about other proposed answers.]