【发布时间】:2014-12-06 10:14:51
【问题描述】:
我面临一些与日期相关的小问题。实际上我正在使用 grails 2.3.7 并尝试根据日期范围查找记录。假设我想获取日期为 26-11-2014 的所有记录。
所以我最终使用了这种方法。
String fromDate="2014-12-03";
String toDate="2014-12-04";
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd")
Date d1 = df1.parse(fromDate);
Date d2 = df1.parse(toDate);
Order?.executeQuery("select orderDate from Order where orderDate between ? and ? ",[d1,d2]);
结果是
[2014-12-03 10:27:23.0, 2014-12-03 10:30:53.0, 2014-12-03 10:32:30.0]
实际上是 03-12-2014 的 4 条记录,但我们只得到了 3 条。
同样的事情适用于 2014-11-27 到 2014-11-28
结果是
[2014-11-27 10:52:56.0, 2014-11-27 13:42:16.0, 2014-11-27 14:44:05.0, 2014-11-27 15:47:36.0,
2014-11-27 15:51:36.0, 2014-11-27 16:10:17.0, 2014-11-27 18:01:08.0, 2014-11-27 18:07:47.0,
2014-11-27 18:30:54.0, 2014-11-27 18:34:06.0, 2014-11-27 18:40:35.0]
实际上 27-11-2014 的 13 条记录,但我们只有 11 条。
请帮帮我。
我卡在这里了。
【问题讨论】:
-
你检查时间了吗?
-
你能描述一下什么是时间
-
当你给 between 子句检查整个日期格式时。就像你提供
2014-12-04but 它提供了这样的东西或其他东西2014-12-04 12:00:00:000 -
是的,我也检查过 SimpleDateFormat("yyyy-MM-dd HH:MM:SS")
-
和 fromDate 和 toDate 值从数据表复制