Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive cast string to date dd-MM-yyyy

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') 
like image 493
pele88 Avatar asked Sep 09 '15 09:09

pele88


People also ask

How do I change data from string to date in Hive?

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.

How do I convert a number to a date in Hive?

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.


1 Answers

try:

from_unixtime(unix_timestamp('12-03-2010' , 'dd-MM-yyyy')) 
like image 157
Ardit Avatar answered Sep 21 '22 10:09

Ardit