How to convert a date format YYYY-MM-DD into integer YYYYMMDD in Presto/Hive?
Also you can use date_format
function:
hive> select cast(date_format('2017-07-01','yyyyMMdd') as int);
OK
20170701
If you just need to transform your date YYYY-MM-DD into an integer YYYYMMDD why don't you try to first remove all the occurrences of "-"
from the string representation of your date before casting the result to int by using something like this?
cast(regexp_replace(str_column,'-','') as int)
Simply REPLACE
the '-' with Empty string and CAST
it into INT
.
Try the following:
SELECT CAST(REPLACE(Date_Column,'-','') AS INT)