Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 需要从蜂箱中给定的时间戳中减去几个小时_Mysql_Sql_Hive_Hiveql_Sql Date Functions - Fatal编程技术网

Mysql 需要从蜂箱中给定的时间戳中减去几个小时

Mysql 需要从蜂箱中给定的时间戳中减去几个小时,mysql,sql,hive,hiveql,sql-date-functions,Mysql,Sql,Hive,Hiveql,Sql Date Functions,输入:unix_时间戳('01/15/2018 15:26:37','mm/dd/YYYY hh:mm:ss') 预期输出比utc输入时间延迟4小时,即2018年1月15日11:26:37 我知道hive中有date_子函数,但它只用于从给定的时间戳中减去天数。但我需要知道是否有一种方法可以减去小时、分钟或秒 我还尝试了以下方法,因为EDT时区比UTC晚4小时(但输出错误): 有人能帮我解决这个问题吗?效果很好 select from_unixtime(unix_timestamp('01/15

输入:unix_时间戳('01/15/2018 15:26:37','mm/dd/YYYY hh:mm:ss')

预期输出比utc输入时间延迟4小时,即2018年1月15日11:26:37

我知道hive中有date_子函数,但它只用于从给定的时间戳中减去天数。但我需要知道是否有一种方法可以减去小时、分钟或秒

我还尝试了以下方法,因为EDT时区比UTC晚4小时(但输出错误):

有人能帮我解决这个问题吗?

效果很好

select from_unixtime(unix_timestamp('01/15/2018 15:26:37', 'MM/dd/yyyy HH:mm:ss')-4*3600, 'MM/dd/yyyy HH:mm:ss') 
除此之外

我发现将长表达式定义为宏并放入初始化文件(例如,
hive-I init-file.hql…
)非常有用

宏从Hive 0.12.0开始提供,可以找到更多详细信息(请注意“bug fixes”部分)

select from_unixtime(unix_timestamp('01/15/2018 15:26:37', 'MM/dd/yyyy HH:mm:ss')-4*3600, 'MM/dd/yyyy HH:mm:ss') 
hive> create temporary macro sub_hours(dt string, hours int)
from_unixtime(unix_timestamp(dt, 'MM/dd/yyyy HH:mm:ss') - 3600 * hours, 'MM/dd/yyyy HH:mm:ss');
OK
Time taken: 0.005 seconds
hive> select sub_hours("01/01/2019 00:00:00", 5);
OK
12/31/2018 19:00:00
Time taken: 0.439 seconds, Fetched: 1 row(s)