在postgresql中,我可以直接使用。
to_char(current_date - 14, 'YYYYMMDD')
然而这不是hive所接受的语法,我也找不到合适的函数来处理这个日期格式。谁能帮帮我?
gz5pxeao1#
在hive中,你通常会使用中间转换为unix时间戳。
from_unixtime(unix_timestamp() - 14 * 24 * 60 * 60, 'yyyyMMdd')
unix_timestamp()将当前的日期/时间作为纪元时间戳返回;然后你可以减去14天(以秒表示),然后使用from_unixtime()将结果格式化为目标格式的字符串。
unix_timestamp()
from_unixtime()
jdg4fx2g2#
对于hive版本>=1.2.0,你可以使用date_format函数,也可以使用date_sub函数。
date_sub
date_format(date_sub(current_date,14),'yyyyMMdd')
2条答案
按热度按时间gz5pxeao1#
在hive中,你通常会使用中间转换为unix时间戳。
unix_timestamp()
将当前的日期/时间作为纪元时间戳返回;然后你可以减去14天(以秒表示),然后使用from_unixtime()
将结果格式化为目标格式的字符串。jdg4fx2g2#
对于hive版本>=1.2.0,你可以使用date_format函数,也可以使用
date_sub
函数。