How can I cast a string in the format 'dd-MM-yyyy' to a date type also in the format 'dd-MM-yyyy' in Hive?
Something along the lines of:
CAST('12-03-2010' as date 'dd-mm-yyyy')
2.3 to_date(string timestamp) – Converts Timestamp string to Date type. to_date() function takes timestamp as an input string in the default format yyyy-MM-dd HH:mm:ss and converts into Date type.
Since your date columns are in integer datatype, cast them as string and use Hive's built-in date functions. Here what you need: select date_format(from_unixtime(unix_timestamp(cast(your-column as string),'yyyyMMHHmm')),'yyyy-MM HH:mm') from table; The above code gave me the following results.
try:
from_unixtime(unix_timestamp('12-03-2010' , 'dd-MM-yyyy'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With