您使用了正确的功能,但参数错误。参数应该是 unix_timestamp(datestring, date_format) ;此函数会将日期转换为 unix 日期格式,您可以使用 from_unixtime(unixdateformat,format_youneed);
进一步格式化
hive> select unix_timestamp('Sep 1 2017 2:00 PM' ,'MMM dd yyyy HH:mm a');
OK
1504256400
你需要特定的日期模式,你可以使用函数
from_unixtime(unixdateformat,format_youneed);
hive> select from_unixtime(1504256400,'dd-MM-yyyy');
OK
01-09-2017
hive> select from_unixtime(UNIX_TIMESTAMP('Sep 1 2017 2:00 PM','MMM dd yyyy
HH:mm a'), 'dd-MM-yyyy');
OK
01-09-2017
Time taken: 0.135 seconds, Fetched: 1 row(s)
由于您将日期存储在表中的实际日期中,您可以使用以下命令来获取结果。
**hive> select from_unixtime(UNIX_TIMESTAMP(actualshipdate,'MMM dd yyyy HH:mm a'), 'dd-MM-yyyy') from tablename;**