11

How to select Data in ms access above this datetime range

like select * from logevents where logTime>='12/6/2012 3:54:15 PM'

logTime is Datetime field

Spen D
  • 4,225
  • 9
  • 39
  • 47

2 Answers2

23

Adding # signs on each end of your date lets Access know that this is a date type.

select * from logevents where logTime>=#12/6/2012 3:54:15 PM#
HelloW
  • 1,587
  • 2
  • 13
  • 24
0

This depends on if your Access database is created/opened in ANSI 92 mode:
non-ANSI 92: Access uses # ... # around dates and uses * (multiple characters) and ? (one character) for wildcards when using LIKE. For example:

SELECT * FROM logevents WHERE logTime>=#12/6/2012# AND description like 'error'

ANSI 92: Access uses ' ... ' around dates and uses % and ? for wildscards when using LIKE. This mode looks more like how MySQL, Oracle and MSSQL work with dates and wildcards. For example:

SELECT * FROM logevents WHERE logTime>='12/6/2012' AND description like '%error%'

Be sure to check the date format settings. It can dd/mm/yyyy or dd-mm-yyyy or something else, this depends on your regional settings. Just inspect your table for a date column for example data.

To switch to ANSI-92 in Access 2007, but this should not be hard to apply to different versions: -open MS Access -click the Office button on top left -click "Access Options" button -select "Object Designers" from the left pane -look for "Query Design" section, there is an option "SQL Server Compatible Syntac (ANSI 92). -if you have an open database, you can check on "This Database" or check the "Default for new databases" for default setup on all new databases -click "OK" button to accept the changes

Jan
  • 2,165
  • 1
  • 18
  • 13