sql - Hive SQL-向现有时间戳添加(不附加)秒
问题描述
我正在尝试将秒数添加到现有时间戳以查找结束时间。我在一个字段中有开始时间,在一个字段中有总持续时间。我怎么能加。我尝试使用 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 功能,不会工作。
解决方案
使用 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()
函数的第二个参数。
推荐阅读
- android - 无法在 android studio 中构建或运行
- python - django-admin 打开一个新项目
- typescript - 来自嵌套对象的 TypeScript 模板文字字符串
- python - 从坐标标签计算 xarray 数据数组
- sql-server - sql server 使用recrusive cte获取同组中的级别
- javascript - Fullcalendar 无法解析本地 JSON
- reactjs - Material UI datetime-local 输入打开日历下拉菜单
- github - 为代码审查拉取请求创建 GitHub 操作分支
- javascript - 让孩子行展开和可编辑的单元格
- image - 将图像添加到markdownfile