【问题标题】:SQL date filterSQL 日期过滤器
【发布时间】:2013-04-17 12:52:14
【问题描述】:

我运行了以下查询,但不知何故我觉得结果有误。

SQL> select to_char(starttime,'dd-mm-YYYY hh24:mi:ss') 
from report 
where dateofmonth between 
    to_timestamp_tz('22-Apr-2013 12:00:00','dd-mm-YYYY hh24:mi:ss') 
    and to_timestamp_tz ('23-Apr-2013 14:00:00','dd-mm-YYYY hh24:mi:ss');

TO_CHAR(STARTTIME,
--------------------
23-04-2013 22:43:59
23-04-2013 13:43:37

SQL> select to_timestamp_tz(starttime,'dd-mm-YYYY hh24:mi:ss') 
from report 
where dateofmonth between 
    to_timestamp_tz('22-Apr-2013 12:00:00','dd-mm-YYYY hh24:mi:ss') 
    and to_timestamp_tz ('23-Apr-2013 14:00:00','dd-mm-YYYY hh24:mi:ss');

TO_TIMESTAMP_TZ(STARTTIME,'DD-MM-YYYYHH24:MI:SS')
-------------------------------------------------
23-APR-13 10.43.59 PM -07:00
23-APR-13 01.43.37 PM -07:00

我不确定为什么结果中会出现晚上 10 点的时间。

【问题讨论】:

  • 是因为dateofmonth对时间不敏感,只检查日期是否正确?
  • 你能帮我让它对时间敏感吗?我不知道该怎么做

标签: sql oracle datetime timestamp


【解决方案1】:

曼吉特,

您正在选择 starttime 列,但 where 子句具有 dateofmonth 列。在您的查询中同时选择 starttime 和 dateofmonth 并检查它是否给出了正确的结果。

【讨论】:

    猜你喜欢
    • 2014-12-21
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多