Hive:以“yyyy-MM-dd”格式计算从日期算起的 1 年时间细绳

发布于 2025-01-13 12:27:07 字数 209 浏览 3 评论 0原文

我需要计算在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2025-01-20 12:27:07

在自 1.2.0 起的较新版本的 Hive 中,您可以在日期中添加间隔

select date('2021-01-29') + interval 1 year

结果:

2022-01-29

对于旧版本的 Hive,请使用此配方:

1 年 = 12 个月。使用 add_months 函数添加 12 个月:

select add_months('2021-01-29',12)

结果:

2022-01-29

如果要添加超过一年,请将 12 乘以年数。

In newer versions of Hive since 1.2.0 you can add interval to the date:

select date('2021-01-29') + interval 1 year

Result:

2022-01-29

For old version of hive use this recipe:

1 Year = 12 months. Add 12 months using add_months function:

select add_months('2021-01-29',12)

Result:

2022-01-29

If you want to add more than one year, multiply 12 by the number of years.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文