配置单元中的任何日期函数都可以选择一个月的星期?

vwkv1x7d  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(302)

hive中有没有日期函数可以选择一个月的星期?
假设一周是从周日到周六,周日是一周的开始日,周六是一周的结束日。
我有一份日期清单,从1900年1月1日到2029年12月31日。我想知道Hive中是否有一个日期函数来获取一个月中的一周。
例如。:

2019-02-01 to 2019-02-02 is the first week of FEB  
2019-02-03 to 2019-02-09 is the second week of FEB..  
2019-02-24 to 2019-02-28 is the 5th week of FEB

我的问题是:

select (weekofyear(date)-weekofyear(trunc(date,'month')) + 1 as Week_of_month

但是,出现了一些错误。在年初,每月的一周是负数。e、 g.1993-01-03 is-51

sirbozc5

sirbozc51#

使用 date_format(date/timestamp/string ts, string fmt) 功能。 W 格式模式是指一个月内的周数。

select date_format('2019-02-01','W');
OK
1
Time taken: 0.076 seconds, Fetched: 1 row(s)

hive> select date_format('1993-01-03','W');
OK
2
Time taken: 0.054 seconds, Fetched: 1 row(s)

其他有用的日期和时间格式模式

相关问题