Sql 将hive中的日期格式(2017年10月4日)转换为(2017年10月4日)

Sql 将hive中的日期格式(2017年10月4日)转换为(2017年10月4日),sql,hive,hiveql,Sql,Hive,Hiveql,我有一个数据库,其日期结果如下表所示 20171004 所以我使用了这个查询 select SUBSTRING(week_first_day_id,1,4) ||'/' || (SUBSTRING(week_first_day_id,5,2)) || '/' || SUBSTRING(week_first_day_id,7,2) from d_date; 结果是 04/10/2017 我想将月份格式更改为周一(2017年10月4日)?使用: 我觉得您没有将日期存储为日期或标准格式。这

我有一个数据库,其日期结果如下表所示

20171004

所以我使用了这个查询

 select SUBSTRING(week_first_day_id,1,4) ||'/' ||
 (SUBSTRING(week_first_day_id,5,2)) || '/' ||
 SUBSTRING(week_first_day_id,7,2)  from d_date;
结果是

04/10/2017
我想将月份格式更改为周一(2017年10月4日)?

使用:

我觉得您没有将日期存储为日期或标准格式。这是一件坏事,您应该修复数据。您可以解析日期并使用它。我认为代码如下所示:

select date_format(from_unix_timestamp(unix_timestamp(week_first_day_id, 'dd/mm/yyyy')))
使用unix_时间戳(字符串日期、字符串模式)将给定的日期格式转换为从1970-01-01传递的秒数。然后使用from_unixtime()转换为所需格式:

hive> select  from_unixtime(unix_timestamp( '20171004','yyyyMMdd'), 'dd-MMM-yyyy');
OK
_c0
04-Oct-2017
Time taken: 1.329 seconds, Fetched: 1 row(s)
hive> select  from_unixtime(unix_timestamp( '20171004','yyyyMMdd'), 'dd-MMM-yyyy');
OK
_c0
04-Oct-2017
Time taken: 1.329 seconds, Fetched: 1 row(s)