Warm tip: This article is reproduced from stackoverflow.com, please click
ms-access sql vba

search date from date time field query not working

发布于 2020-04-05 00:23:07

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.

Questioner
Tarun. P
Viewed
58
Eric Brandt 2020-01-31 23:07

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.