将 hh 中的时间戳转换为日期

发布于 2025-01-17 07:42:05 字数 191 浏览 1 评论 0原文

我在Hive列中具有这种数据格式。

09/05/2015  12:45:00

我试图将其转换为这种格式,


20150905, or with semicolons - 2015-09-05

最有效的方法是什么,而无需浏览Linux时间戳?

I have this format of data in a hive column.

09/05/2015  12:45:00

I am trying to convert it to this format


20150905, or with semicolons - 2015-09-05

What is the most efficient way and without going through linux timestamp?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生池水覆流年 2025-01-24 07:42:05

使用date_format
如果您的数据为字符串/时间戳/日期格式,
而且您需要一串格式yyyy-mm-dd,然后使用 -
date_format(date_time_col,'yyyy-mm-dd')
而且您想要日期格式,然后使用 -
cast(date_format(date_time_col,'yyyy-mm-dd')作为日期)

edit
如果您有一个字符串的“ mm/dd/yyyy”,则需要将字符串分开并置为cont,然后将它们发送到date_format。

date_format( 
concat_ws('-', substr(split(date_time_col,'/')[2],1,4),split(date_time_col,'/')[0], split(date_time_col,'/')[1] )
, 'yyyy-MM-dd') 

您可以将所有这些结合在一起 -

case when date_format(date_time_col, 'yyyy-MM-dd') is null 
date_format( 
concat_ws('-', substr(split(date_time_col,'/')[2],1,4),split(date_time_col,'/')[0], split(date_time_col,'/')[1] )
, 'yyyy-MM-dd') 
else date_format(date_time_col, 'yyyy-MM-dd')
end

use date_format.
If your data is in String/Timestamp/Date format,
and you want a string of format yyyy-MM-dd, then use-
date_format(date_time_col, 'yyyy-MM-dd')
and you want a date format , then use-
cast( date_format(date_time_col, 'yyyy-MM-dd') as date)

EDIT
In case you have a string 'MM/dd/yyyy', you need to split the string and concat them before senting them to date_format.

date_format( 
concat_ws('-', substr(split(date_time_col,'/')[2],1,4),split(date_time_col,'/')[0], split(date_time_col,'/')[1] )
, 'yyyy-MM-dd') 

And you can combine all like this -

case when date_format(date_time_col, 'yyyy-MM-dd') is null 
date_format( 
concat_ws('-', substr(split(date_time_col,'/')[2],1,4),split(date_time_col,'/')[0], split(date_time_col,'/')[1] )
, 'yyyy-MM-dd') 
else date_format(date_time_col, 'yyyy-MM-dd')
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文