AddyProg
AddyProg

Reputation: 3050

Date string Comparison not working (MS ACCESS 2010)

I am trying to get specific record by comparing date string. Here is the table

UpdateTimeA          -     UpdateUserId
----------------------------------------
2015/09/02 14:39:39  -     User1
2015/09/02 16:57:29  -     User2
2015/09/02 16:58:37  -     User3

And here is the query

SELECT UpdateUserId, UpdateTimeA From SubmitSheets 
WHERE UpdateTimeA =DateValue('9/2/2015 4:58:37 PM')

This query returns 0 records UpdateTimeA is a DateTime type field.

Upvotes: 0

Views: 43

Answers (2)

Gustav
Gustav

Reputation: 56006

No need to use Format:

SELECT UpdateUserId, UpdateTimeA
From SubmitSheets
WHERE UpdateTimeA = #9/2/2015 4:58:37 PM#

Or you can use the serial functions:

SELECT UpdateUserId, UpdateTimeA
From SubmitSheets
WHERE UpdateTimeA = DateSerial(2015, 9, 2) + TimeSerial(16, 58, 37)

Upvotes: 1

Roman Marusyk
Roman Marusyk

Reputation: 24619

Please try to use something like this:

SELECT UpdateUserId, UpdateTimeA
From SubmitSheets
WHERE Format(UpdateTimeA, "m/d/yyyy hh:nn:ss AM/PM") = '9/2/2015 4:58:37 PM'

Upvotes: 0

Related Questions