简体   繁体   English

Oracle查询日期和时间

[英]Oracle querying date and time

I am trying to get data from a table where start_date is less than or equal to a particular date and time value: 我正在尝试从其中start_date小于或等于特定日期和时间值的表中获取数据:

SELECT * FROM Table1 WHERE START_DATE <= TO_DATE('2/21/2018 2:40:20 PM', 'MM/dd/yyyy hh:mm:ss tt')

The error I am getting is format code appears twice 我收到的错误是format code appears twice

I have tried different formats but still cannot get it right 我尝试了不同的格式,但仍然无法正确处理

You have two problems. 你有两个问题。

1) The format model for minutes is "mi", not "mm". 1)分钟的格式模型是“ mi”,而不是“ mm”。

2) The format model for AM/PM is "AM", not "tt". 2)AM / PM的格式模型是“ AM”,而不是“ tt”。

So, 所以,

TO_DATE('2/21/2018 2:40:20 PM', 'MM/dd/yyyy hh:mi:ss AM')

Or, easier, 或者,更容易

TO_DATE('2/21/2018 14:40:20', 'MM/dd/yyyy hh24:mi:ss')

(ie, a 24-hour clock) (即24小时制)

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

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