MS Access 2007: date query

后端 未结 2 933
臣服心动
臣服心动 2021-01-22 07:36

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?

2条回答
  •  逝去的感伤
    2021-01-22 07:57

    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#
    

提交回复
热议问题