Hive:以“yyyy-MM-dd”格式计算从日期算起的 1 年时间细绳
我需要计算在 HIVE 中从该日期“2021-01-29”开始是否已经过去了整整 1 年或更长时间。 因此结果日期必须采用“yyyy-MM-dd”格式,并且等于“2022-01-29”或更高版本。 “2022-01-28”这不是正确答案。
可以使用date_add('2021-01-29',间隔1年)
,如果可以,有人可以解释一下如何吗?
先感谢您。
I need to calculate if has passed exactly 1 year or more from this date '2021-01-29', in HIVE.
So the result date must be in 'yyyy-MM-dd' format, and equal to '2022-01-29' or later. '2022-01-28' it's not correct answer.
It's possible to use date_add('2021-01-29', interval 1 year)
, if so, could someone explain how?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在自 1.2.0 起的较新版本的 Hive 中,您可以在日期中添加间隔:
结果:
对于旧版本的 Hive,请使用此配方:
1 年 = 12 个月。使用 add_months 函数添加 12 个月:
结果:
如果要添加超过一年,请将 12 乘以年数。
In newer versions of Hive since 1.2.0 you can add interval to the date:
Result:
For old version of hive use this recipe:
1 Year = 12 months. Add 12 months using add_months function:
Result:
If you want to add more than one year, multiply 12 by the number of years.