Hive SQL-将(不附加)秒添加到现有时间戳

时间:2019-06-12 16:58:12

标签: sql hive

我正在尝试将秒数添加到现有时间戳中以查找结束时间。 我在一个字段中有开始时间,在一个字段中有总持续时间。我怎么可以添加。我尝试使用date_add函数,但是不起作用。

Select
      testdate, 
      DATE_ADD ( testdate,CAST (testduration as INT) ) as Test_end_date  
from <DBName>  limit 10;
TestDate is this format= 9/14/2017 16:33:25.000000
Testduration is in seconds e.g: 144 seconds or so

它将添加到日期而不是秒部分。

感谢您的帮助。

尝试过Date_Add函数,将无法工作。

1 个答案:

答案 0 :(得分:0)

使用unix_timestamp转换为秒,添加秒

select from_unixtime(UNIX_TIMESTAMP('9/14/2017 16:33:25.000000','M/dd/yyyy HH:mm:ss.SSSSS')+144, 'yyyy-MM-dd HH:mm:ss.SSSSS')

这将以标准Hive时间戳格式返回时间戳,如果需要保留原始格式,请更改输出格式:'M / dd / yyyy HH:mm:ss.SSSSS'作为from_unixtime()函数的第二个参数。 / p>

查看此测试:http://demo.gethue.com/hue/editor?editor=53060