如何正确设置 DateTime 值的 ADODB.Recordset.Filter 属性?
我有一个 ADODB 2.x 记录集,并尝试将过滤器应用于记录集中的日期时间列/字段。
我不知道如何在 Windows 中配置国际日期格式设置。通过大量谷歌搜索,我不完全确定 Windows 日期格式设置是否确定了 Filter 属性所需的日期格式,或者是否始终采用美国日期格式。 (当然,MS文档没有注意到这
一点。)那么,如何正确编写这一行代码,这样我就不必担心用户在Windows中配置了什么日期格式:
rs.Filter = "StartDateTime >= " & dteStartDate
...where dteStartDate 包含日期和时间组件。
I have an ADODB 2.x recordset and am trying to apply a filter to a DateTime column/field in the recordset.
I do not know how the has configured their international date format settings in Windows. From lots of googling, I am not entirely sure if the windows date format settings determines the required date format for the Filter property, or whether it is always expected in US date format. (Of course, the MS documentation makes no note of this.)
So, how does one properly write this line of code, so I don't have to worry what date format the user has configured in Windows:
rs.Filter = "StartDateTime >= " & dteStartDate
...where dteStartDate contains both a Date and Time component.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
过滤器的格式需要与记录集中的值格式相同。我刚刚在 MS SQL 服务器的记录集上遇到了同样的问题。记录集包含 YYYY-MM-DD 格式的日期。
失败:
即使日期匹配,筛选的记录集中也没有记录。选中时,CalendarRS.filter 中存储的值是“DateField = #08/29/2014#” 请注意,这包含正斜杠并且顺序不同 (MM/DD/YYYY)
成功:
选中时,存储的值在 CalendarRS.filter 中为“DateField = #2014-08-2014#”。这返回了正确的过滤记录集。
对于完整的日期和时间,您需要执行相同的操作并添加小时、分钟、秒。
The format of the filter needs to be in identical format as the value in the recordset. I just ran into the same issue with a recordset from a MS SQL server. the recordset contained a date in YYYY-MM-DD format.
This failed:
Even if the date matched, no records were in the filtered recordset. When checked, the value stored in CalendarRS.filter was "DateField = #08/29/2014#" Note that this contains forward slashes and that the order is different (MM/DD/YYYY)
This succeeded:
When checked, the value stored in CalendarRS.filter was "DateField = #2014-08-2014#". This returned the correct filtered recordset.
For a full date and time, you need to do the same thing and add hour, minute, second.