使用dd / mm / yyyy的访问日期查询返回零 [英] Access date query using dd/mm/yyyy returns zero found
问题描述
我的访问数据库以 DD / MM / YYYY
格式显示日期。一行包含日期为 07/06/2014
,但我的查询说找不到。
My Access database displays dates in DD/MM/YYYY
format. One row contains date as 07/06/2014
, but my query says "not found".
这里是我的选择查询:
strSql = "SELECT * FROM Tbl WHERE MyDate = #" & Me.fldFindWhat.Value & "#"
MsgBox strSql
显示
MsgBox strSql
displays
SELECT * FROM Tbl WHERE MyDate = #07/06/2014#
那么问题在哪里?
推荐答案
这是一个常见的对于使用 dd / mm / yyyy
格式的用户的Access日期查询问题。问题是Access数据库引擎不关心Windows本身的区域设置; 总是解释 #xx / yy / zzzz#
日期文字为 mm / dd / yyyy
。令人困惑的是,它会将明确的 #xx / yy / zzzz#
日期文字解释为 dd / mm / yyyy
如果 xx
大于12。
This is a common issue with Access date queries for people who use the dd/mm/yyyy
format. The problem is that the Access Database Engine does not pay any attention to the Regional Settings in Windows itself; it always interprets ambiguous #xx/yy/zzzz#
date literals as mm/dd/yyyy
. Adding to the confusion is the fact that it will interpret unambiguous #xx/yy/zzzz#
date literals as dd/mm/yyyy
if xx
is greater than 12.
所以,Access数据库引擎会将#13/06/2014#
解释为 2014年6月13日
。日期文字是无歧义的,因为没有第13个月。
So, the Access Database Engine will interpret #13/06/2014#
as June 13, 2014
. The date literal is unambiguous since there is no 13th month.
但是,Access数据库引擎将始终解释# 07/06/2014#
as 2014年7月6日
。无论Windows控制面板中的区域设置如何,都是如此。
However, the Access Database Engine will always interpret #07/06/2014#
as July 6, 2014
. This is true regardless of the Regional Settings in the Windows Control Panel.
为避免此问题,请始终使用明确的 yyyy / mm / dd
格式在日期文字中,例如
To avoid this problem, always use the unambiguous yyyy/mm/dd
format in date literals, e.g.,
strSql = "SELECT * FROM Tbl WHERE MyDate = #" & _
Format(Me.fldFindWhat.Value, "yyyy\/mm\/dd") & "#"
您还可以使用 mm / dd / yyyy
格式在日期文字中,例如
You could also use the mm/dd/yyyy
format in date literals, e.g.,
strSql = "SELECT * FROM Tbl WHERE MyDate = #" & _
Format(Me.fldFindWhat.Value, "mm\/dd\/yyyy") & "#"
...但是以前看过 dd / mm / yyyy
日期可能会在分析调试输出时发现这个混乱。
... but people who are used to seeing dd/mm/yyyy
dates could find this confusing when analyzing debug output.
这篇关于使用dd / mm / yyyy的访问日期查询返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!