hive 3.0.0 want to convert timestamp to string with a mask

2.8k Views Asked by At

I have to revert a date conversion At the beginning it was

CAST(FROM_UNIXTIME(UNIX_TIMESTAMP(t0.date_creation , 'yyyyMMdd'T'hhmmss')) AS TIMESTAMP)

Now I'm looking on how to convert a timestamp to the format 'yyyyMMdd'T'hhmmss'

the syntax CAST(date_creation as string format 'yyyy-MM-dd hh:mm:ss') is not working

1

There are 1 best solutions below

3
On

Use date_format function:

select current_timestamp, date_format(current_timestamp,"yyyyMMdd'T'HHmmss") as result;

Returns:

2020-10-09 15:03:36.584       20201009T150336

Read about format here: SimpleDateFormat