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
i tried this code
but i got the error showing below
Then i tried this code
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 9:00 AM and 11:30 AM on 2/23/2009, but I can see there are records.
Then i tried this code
And when I use TimeValue, it returns the time from the string and set date as jan 1st. so it returns no records between 9:00 AM and 11:30 AM on 2/23/2009, but I can see there are records.
Then i tried this code
but none of the codes above is returning records between 9:00 AM and 11: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 9:00 AM and 11: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.
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
So I need to find all the records in between 9:00 AM and 11:30 AM on 2/23/2009.StartTime = “2/23/2009 9:00:00 AM”
EndTime = “2/23/2009 11:30:00 AM”
i tried this code
VB.NET:
strSQL = "select OrderID from Orders Where OrderDate >= ('" & StartTime & "') AND OrderDate <= ('" & EndTime & "') "
but i got the error showing below
An unhandled exception of type 'System.Data.OleDb.OleDBException' occured in system.data.dll
Then i tried this code
VB.NET:
strSQL = "select OrderID from Orders Where OrderDate >= DATEVALUE('" & StartTime & "') AND OrderDate <= DATEVALUE('" & EndTime & "') "
Then i tried this code
VB.NET:
strSQL = "select OrderID from Orders Where OrderDate >= TimeValue('" & StartTime & "') AND OrderDate <= TimeValue('" & EndTime & "') "
Then i tried this code
VB.NET:
strSQL = "select OrderID from Orders Where (OrderDate BETWEEN DATEVALUE('" & StartTime & "') AND DATEVALUE('" & EndTime & "')) "
VB.NET:
strSQL = "select OrderID from Orders Where (OrderDate BETWEEN ('" & StartTime & "') AND ('" & EndTime & "')) "
but none of the codes above is returning records between 9:00 AM and 11: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 9:00 AM and 11: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.
Last edited: