【发布时间】:2017-12-15 16:23:25
【问题描述】:
我想要每个月的最后一个日期,例如 1 月 31 日、2 月 28 日等。 我在下面尝试了 current_date 并且它可以工作,但是当我使用我的日期列时它返回 null:
SELECT datediff(CONCAT(y, '-', (m + 1), '-', '01'), CONCAT(y, '-', m, '-', '01')) FROM
(SELECT
month(from_unixtime(unix_timestamp(C_date, 'yyyyMMdd'),'yyyy-MM-dd') ) as m,
year(from_unixtime(unix_timestamp(C_date, 'yyyyMMdd'),'yyyy-MM-dd') ) as y,
day(from_unixtime(unix_timestamp(C_date, 'yyyyMMdd'),'yyyy-MM-dd') )
from table2 ) t
返回:
_c0
NULL
SELECT
month(from_unixtime(unix_timestamp(C_date, 'yyyyMMdd'),'yyyy-MM-dd') ) as m,
year(from_unixtime(unix_timestamp(C_date, 'yyyyMMdd'),'yyyy-MM-dd') ) as y,
day(from_unixtime(unix_timestamp(C_date, 'yyyyMMdd'),'yyyy-MM-dd') )
from table2) t
返回:
m | y | _c2|
3 |2017| 21|
提前致谢。
【问题讨论】:
-
select last_day(current_date) - 返回完整日期 2017-12-31 ,我只需要 31 所以除非我 substr 我不会得到 31
-
hive 中有日历实用程序,请尝试使用 hive UDF 函数