在PostgreSQL中,我只需要使用以下代码:
然而,在Hive中,这不是一种被接受的语法,我找不到适用于此日期格式的正确函数。请问是否有人可以帮忙?
to_char(current_date - 14, 'YYYYMMDD')
然而,在Hive中,这不是一种被接受的语法,我找不到适用于此日期格式的正确函数。请问是否有人可以帮忙?
对于 Hive 版本 >= 1.2.0,您可以使用 date_format 函数。 同时,date_sub
函数也可用:
date_format(date_sub(current_date,14),'yyyyMMdd')
from_unixtime(unix_timestamp() - 14 * 24 * 60 * 60, 'yyyyMMdd')
unix_timestamp()
将当前日期/时间作为纪元时间戳返回;然后您可以减去14天(以秒为单位),然后使用from_unixtime()
将结果格式化为目标格式的字符串。