【问题标题】:Coverting epoch time value into a timestamp(6) in teradata将纪元时间值转换为 teradata 中的时间戳(6)
【发布时间】:2019-10-16 08:18:42
【问题描述】:

如何将纪元时间值转换为 teradata 中的时间戳 (6)?

让我们以 1336987231051 作为示例纪元时间(注意这是以毫秒为单位,而纪元时间以秒为单位),我做了这样的事情

// miliseconds epoch time 
select cast(1336987231051 as timestamp(6))

// seconds epoch time 
select cast((1336987231051/1000) as timestamp(6))

我收到上述两个选择语句的错误消息:

[Error] Script lines: 12-12 ------------------------
[Teradata Database] [TeraJDBC 13.10.00.31] [Error 5407] [SQLState HY000] Invalid operation for DateTime or Interval. 

我在http://www.epochconverter.com/ 中验证了 1336987231051 是有效的纪元时间。

在 teradata 中正确的 sql 是什么?

【问题讨论】:

    标签: sql teradata


    【解决方案1】:
    select
        cast(cast(700101 as date) + seconds_from_epoch / 86400 as timestamp(6)) +
            (seconds_from_epoch mod 86400) * interval '00:00:01' hour to second
    from my_table
    

    【讨论】:

      【解决方案2】:

      将 EPOCH 转换为 TERADATA TIME 的最简单方法。

      SELECT
         1336987231051/1000 as unix_epoc_time   ,
         to_timestamp(unix_epoc_time) utc,
         cast(cast(utc as char(19))||'+00:00' as timestamp(0) with time zone) AT LOCAL    
      ;
      
      1. 如果您的纪元是 10 位,则不需要 /1000
      2. 记住,Unix 时间是 UTC。
      3. 您的系统会将这个“UTC”视为本地。因此,让我们通过添加“+00:00”来了解它是 UTC,然后使用 AT LOCAL 或使用“America Central”、“America Eastern”、“America Mountain”等任何一个将其转换为您的 LOCAL .

      【讨论】:

        猜你喜欢
        • 2017-07-02
        • 2014-10-12
        • 2022-07-20
        • 2021-01-18
        • 1970-01-01
        • 1970-01-01
        • 2020-06-24
        • 2018-02-10
        • 1970-01-01
        相关资源
        最近更新 更多