MS Access 2007: date query

爷,独闯天下 提交于 2019-12-31 03:41:08

问题


I need help with date queries in MS Access 2007.

How do I show all data between date:01/06/2010 time:10:51 and date:13/07/2010 time:22:30?


回答1:


If you are using the query design window you have a lot more latitude than if you are working in VBA. In the query design window you can enter a date and time on the criteria line in the format for your locale, when viewed in SQL view, you might see:

SELECT tbl.CrDate
FROM tbl
WHERE tbl.CrDate Between #2/5/2006 14:7:0# And #11/18/2006 17:28:15#

However, it is generally best to enter dates in year/month/day or year-month-day format, even though Access may change it to your locale format. In VBA it is a different story, Access needs month,day,year order or year,month,day. Once again, year,month,day is better.

As regards your problem, if you have separated the date and time fields, it would be best to reunite them for the query, you can use + :

DateField + TimeField Between #01/06/2010 10:51# And #13/07/2010 22:30#



回答2:


I have not used MS Access for years, so this is only from memory: Access uses # instead of ' for date values. And you need to use ISO format:

WHERE datecolumn >= #2010-06-01 10:51# AND datecolumn <= #2010-07-13 22:30#


来源:https://stackoverflow.com/questions/3695144/ms-access-2007-date-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!