I’m using VB.net 2003 application program.
I am trying to do a select statement whereby I'm searching between 2 datetime values that are being stored as datetime. records are stored inside Access.
For example, I’m searching between 2 datetime
Quote:
StartTime = “2/23/2009 10:00:00 AM”
EndTime = “2/23/2009 12:30:00 AM”
So I need to find all the records in between 10:00 AM and 12:30 AM on 2/23/2009.
i tried this code
-
strSQL = "select OrderID from Orders Where OrderDate >= ('" & StartTime & "') AND OrderDate <= ('" & EndTime & "') "
-
but i got the error showing below
Quote:
An unhandled exception of type 'System.Data.OleDb.OleDBException' occured in system.data.dll
Then i tried this code
-
strSQL = "select OrderID from Orders Where OrderDate >= DATEVALUE('" & StartTime & "') AND OrderDate <= DATEVALUE('" & EndTime & "') "
-
But when I use DATEVALUE, it takes the date from the string and set time as midnight (00:00:00). So it returns no records between 10:00 AM and 12:30 AM on 2/23/2009, but I can see there are records.
Then i tried this code
-
strSQL = "select OrderID from Orders Where OrderDate >= TimeValue('" & StartTime & "') AND OrderDate <= TimeValue('" & EndTime & "') "
-
And when I use TimeValue, it returns the time from the string and set date as jan 1st. so it returns no records between 10:00 AM and 12:30 AM on 2/23/2009, but I can see there are records.
Then i tried this code
-
strSQL = "select OrderID from Orders Where (OrderDate BETWEEN DATEVALUE('" & StartTime & "') AND DATEVALUE('" & EndTime & "')) "
-
-
strSQL = "select OrderID from Orders Where (OrderDate BETWEEN ('" & StartTime & "') AND ('" & EndTime & "')) "
-
but none of the codes above is returning records between 10:00 AM and 12:30 AM on 2/23/2009, but I can see there are records.
i searched and found all those examples. but that didn't work. Is there anyway i can search between 2 datetime values. i need to find all the records that lies between that time period (for example: between 10:00 AM and 12:30 AM on 2/23/2009).
If you have any idea how to do this, please let me know. if you can provide an example, then that will be great help for me.
Thanks in advance.