首页 > 解决方案 > 从 dt=2018-12-01T18:23:59.000Z 到 dt 的 Hive 日期转换 - 5 小时,格式为 12/1/2018 13:23(即 'MM/dd/yyyy hh:mm' )

问题描述

我写了以下查询:

select call_begin_date_time,
       from_unixtime(unix_timestamp(replace(call_begin_date_time,'T',' '),
       'yyyy-MM-dd hh:mm')-5*3600, 'MM/dd/yyyy hh:mm') as call_begin_dt_time_conv
FROM datawarehouse.charged_usage_fact
where partition_date = '201812' and universalid = '6002163910'
  and billing_start_date = '2018-12-01' and record_validity_flag = 'Valid'
limit 1000;

其中,call_begin_date_time取值如下:2018-12-03T18:05:36.000Z

上述查询的输出如下所示:

call_begin_date_time    ,   call_begin_dt_time_conv   
2018-12-01T23:03:46.000Z ,  12/01/2018 06:03   (wrong)
2018-12-01T22:32:33.000Z ,  12/01/2018 05:32  (wrong)
2018-12-01T16:32:35.000Z ,  12/01/2018 11:32 (right)
2018-12-02T17:01:27.000Z ,  12/02/2018 12:01  (right)
2018-12-02T17:01:35.000Z ,  12/02/2018 12:01  (right)
2018-12-02T17:07:42.000Z ,      12/02/2018 12:07 (right)
2018-12-02T17:12:56.000Z ,  12/02/2018 12:12 (right)
2018-12-02T17:02:11.000Z ,  12/02/2018 12:02 (right)
2018-12-02T17:06:20.000Z ,  12/02/2018 12:06 (right)

对于2018-12-01T23:03:46.000Z,我希望 call_begin_dt_time_conv 显示为'12/01/2018 18:03' (i.e 24 hour format)'12/01/2018 06:03 PM' (i.e 12 hour format)

标签: sqlhivehiveql

解决方案


在您的日期格式中使用HH而不是hh获取 24 小时时间值

'MM/dd/yyyy HH:mm'

推荐阅读