1

I want each month last date ,like Jan - 31 , Feb - 28 , so on. I tried below with current_date and it works but when I use my date column it returns 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

returns :

_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

returns:

m   | y  | _c2|
3   |2017|  21|

Thanks in advance.

Kaushik Nayak
  • 30,772
  • 5
  • 32
  • 45
DrSD
  • 151
  • 2
  • 12

1 Answers1

0

Use last_day() and day() functions:

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

Apply to_date() to convert your column before applying last_day().

leftjoin
  • 36,950
  • 8
  • 57
  • 116