为什么不包括2005-11-30的值?

游戏Lan 2005-12-14 10:14:32
oo0select thread_title,threadID from JB_thread where postuserid=428 and (posttime BETWEEN #2005-11-01# and #2005-11-30#)



posttime 是ACCESS时间类型字段 包含2005-11-30的数据


但查询结果并没有2005-11-30的数据?
为什么?如何解决?
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
changechange 2005-12-14
  • 打赏
  • 举报
回复
请参考以下文章及其相关文章:

字段默认值设定为NOW为什么查不到明明存在的2005-11-30的值?
http://access911.net/?kbid;72FAB11E16DCECF3

OracleRoob 2005-12-14
  • 打赏
  • 举报
回复
因为posttime带有时间,所以不包含
changechange 2005-12-14
  • 打赏
  • 举报
回复
如果你的 posttime 的默认值是 NOW ,那么数据库中 posttime 字段存储的值类似

2005-11-30 12:00:25

如果你用 SQL

select thread_title,threadID from JB_thread where postuserid=428 and (posttime BETWEEN #2005-11-01# and #2005-11-30#)

来搜索值,那么 JET DB 会自动给你加上

select thread_title,threadID from JB_thread where postuserid=428 and (posttime BETWEEN #2005-11-01 00:00:00# and #2005-11-30 00:00:00#)


00:00:00 你想不要都不行。解决方法是

直接写 SQL 代码如下
select thread_title,threadID from JB_thread where postuserid=428 and (posttime BETWEEN #2005-11-01 00:00:00# and #2005-11-30 23:59:59#)

或者

select thread_title,threadID from JB_thread where postuserid=428 and format(posttime,"yyyy-mm-dd")>='2005-11-01' and format(posttime,"yyyy-mm-dd")<='2005-11-30'

注意, FORMAT 函数需要 ACCESS DRIVER 支持,如果你是 vb+JETDB 等方法开发,可能不支持。
wwwwb 2005-12-14
  • 打赏
  • 举报
回复
代码应该可以,检查一下记录内容。
游戏Lan 2005-12-14
  • 打赏
  • 举报
回复
posttime 用的日期类型 设默认值为NOW()
数据库中有2005-11-1 到2005-12-12的所有记录(每天都有记录)
但查2005-11-1 到2005-11-30 的记录,惟独少2005-11-30 这一天的
wwwwb 2005-12-14
  • 打赏
  • 举报
回复
字段是否是日期时间型?将表及要求结果贴出来看看。

7,714

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧