【问题标题】:Date type conversion in hiveHive 中的日期类型转换
【发布时间】:2016-11-03 12:51:12
【问题描述】:

我有一个“MM/dd/yyyy”格式的字符串类型的日期列。 我必须将其转换为“dd/MM/yyyy”格式。

如何在 Hive/Impala 中实现这一点?

【问题讨论】:

    标签: hive impala


    【解决方案1】:

    你可以这样使用,

    select from_unixtime(unix_timestamp(date ,'MM/dd/yyyy'), 'dd/MM/yyyy') from date_test;
    

    让我知道这是否有效。

    【讨论】:

    • 没有Sathiyan。我已经尝试过了,但它没有用。它的输出为 NULL
    • ` 从 date_test 中选择 *;好的 2016 年 12 月 22 日```
    • 从 date_test 中选择 from_unixtime(unix_timestamp(date ,'MM/dd/yyyy'), 'dd/MM/yyyy');
    • 它给了我 22/12/2016 让我知道我是否遗漏了什么。
    【解决方案2】:

    由于您只需要切换现有的子字符串,您可以使用substring:

    concat_ws('/',substr(date,1,2),substr(date,4,2),substr(date,7,4))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 2018-10-19
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多