经常会遇到日期转成字符串,有的字符串带‘-’有的没有,有‘-’的可以直接使用to_date()函数可以实现自动转换,但是有时候我们比较的日期一个是带‘-’的,一个是不带‘-’的,所以需要拉齐,使用以下代码可以快速帮助你应对不用的格式类型的数据,希望对你有帮助。
时间转换】: 2021-05-01 转变成20210501
year(a.event_time)*10000+month(a.event_time)*100+day(a.event_time)
【时间转换】: 20210501 转变成 2021-05-01
concat_ws('-',cast(substring(date,1,4) as string),cast(substring(date,5,2)
as string ),cast(substring(date,7,2) as string) ) as new_date
----------------分享完毕,解决请【点赞】哈 ------------------------
Address:北京
Date:20210511
喜欢可以关注【小猪课堂】公众号了解更多内容