I have below query
sql_query = "select * from bericht where fromtime = " & Me.von & " and b_date = #" & Me.l_date & "#"
it print following line by debug.
select * from bericht where fromtime = 6 and b_date = #1/30/2020#
in table the b_date
is dateTime field
. ( linked table from SQL server in Msaccess)
in this table there is data exist with 1/30/2020 2:00:00 PM
where fromtime
is also 6.
why query didn't return any data?
can msaccess cannot search date in datetime field?
PS: fromtime
is intiger not time field.
Because #1/30/2020#
<> 1/30/2020 2:00:00 PM
.
Convert the column to a date, rather than a datetime, before you do the comparison.
... and DateValue(b_date) = #" & Me.l_date & "#"
This will return all rows from that date that meet your other condition.
it works. that means ms access didn't consider my values as date until i used DateValue.
No, that's not quite it. When comparing a date to a datetime, Access, and every other database that I'm aware of, assumes that the date has a time value of midnight. So you were comparing
1/30/2020 2:00:00 PM
to1/30/2020 12:00:00 AM
. Those are different values, so there was no match. Using theDateValue
function strips the time off of the value in the table and just compares the dates, ignoring the time component.