【问题标题】:to_char on a date field giving unexpected results日期字段上的 to_char 给出意外结果
【发布时间】:2019-06-20 17:35:44
【问题描述】:

看看下面的两个语句,谁能告诉我为什么第二个语句的时间是“11:07”。鉴于第一条语句返回 23:00,我期待“11:00 PM”的时间。

 select early_shpdte
   from shipment
  where ship_id = '3644783_02_94874_5835330-01'

结果:07-09-2019 23:00:00

 select to_char(early_shpdte, 'MM/DD/YYYY HH:MM AM')
   from shipment
  where ship_id = '3644783_02_94874_5835330-01'

结果:2019 年 7 月 9 日晚上 11:07

【问题讨论】:

    标签: sql oracle datetime


    【解决方案1】:

    您已经使用了两次MM,因此时间部分中的“分钟”值实际上是月份数。你想要:

    select to_char(early_shpdte, 'MM/DD/YYYY HH:MI AM')
    --------------------------------------------^^
      from shipment
     where ship_id = '3644783_02_94874_5835330-01'
    

    格式模型元素为in the documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 2012-01-23
      • 2018-04-25
      • 1970-01-01
      • 2019-03-06
      • 2018-09-22
      • 1970-01-01
      相关资源
      最近更新 更多