2017-12-15 13 views
1

毎月の最終日はJan-31、Feb-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| 

感謝を。

+1

[ハイブで1ヶ月の最後の日を検索](https://stackoverflow.com/questions/17548584/find-last-day-of-a-month-in-hive) –

+0

選択可能last_day(current_date ) - 完全な日付を返す2017-12-31、私はsubstrを持たない限り31だけ必要です。 – DrSD

+0

ハイブにカレンダーユーティリティがあるので、ハイブUDF関数を試してみてください –

答えて

0

使用last_day()day()機能:

hive> select day(last_day(current_date)) ; 
OK 
31 
Time taken: 0.079 seconds, Fetched: 1 row(s) 

last_day()を適用する前に列を変換するto_date()を適用します。

関連する問題