简体   繁体   English

我如何在今天午夜到现在之间获取数据?

[英]How do I get data between midnight today and NOW?

As the title suggests, I'm simply trying to get the result set between midnight today and right now. 就像标题所暗示的那样,我只是想在今天午夜到现在之间获取结果集。 So given the time of this post, I want data between 06/30/16 00:00:00 and 06/30/16 15:52:00. 因此,鉴于发布该文章的时间,我希望获得06/30/16 00:00:00到06/30/16 15:52:00之间的数据。 Why does the below query not return anything? 为什么以下查询不返回任何内容? Thanks. 谢谢。

SELECT * FROM tableName
WHERE event_date >= TO_DATE(TRUNC(SYSDATE) || ' 00:00:00', 'DD-MON-YY HH24:MI:SS')
AND event_date <= TO_DATE(TRUNC(SYSDATE))
SELECT *
FROM   tableName
WHERE  event_date BETWEEN TRUNC(SYSDATE) AND SYSDATE;

The solution was as follows: 解决方法如下:

SELECT * FROM tableName
WHERE event_date >= TO_DATE(TRUNC(SYSDATE))

I had forgotten that TRUNC(**SYSDATE )** by itself is perceived as midnight unless otherwise specified, so this does the trick. 我已经忘记,除非另有说明,否则TRUNC(** SYSDATE )**本身被视为午夜,因此可以达到目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM