You are trying to cast 01-Jan-2019 to timestamp, but even if it worked, timestamp in Hive is not in format required: dd-MM-yyyy. timestamp has this format: 'yyyy-MM-dd HH:mm:ss.SSSSSSSSS' (nanoseconds are optional).
unix_timestamp function converts given format string to unix timestamp in seconds, from_unix_time converts unix timestamp to given format.
Use from_unixtime(unix_timestamp(concat('01-',month,'-',year),'dd-MMM-yyyy'),'dd-MM-yyyy') to convert from 'dd-MMM-yyyy' to 'dd-MM-yyyy'
Demo:
with
your_data as (
select stack(2,
2020, 'January',
2019, 'October'
) as ( Year, Month)
)
select Year, Month, from_unixtime(unix_timestamp(concat('01-',month,'-',year),'dd-MMM-yyyy'),'dd-MM-yyyy') as Date_col
from your_data
;
Result:
year month date_col
2020 January 01-01-2020
2019 October 01-10-2019
Also this will work (without concat with 01-, using 'MMM-yyyy' format):
from_unixtime(unix_timestamp(concat(month,'-',year),'MMM-yyyy'),'dd-MM-yyyy')
If you want to convert to true Timestamp, do the same without specifying output format:
from_unixtime(unix_timestamp(concat(month,'-',year),'MMM-yyyy')) --returns 2020-01-01 00:00:00
Use SimpleDateFormat class docs as a format reference