-- 方法一
select concat(substr('20210923',1,4),'-',substr('20210923',5,2),'-',substr('20210923',-2)) date
-- 方法二
select regexp_replace('20200901','([0-9]{4})([0-9]{2})([0-9]{2})','$1-$2-$3') date
-- 方法一
select from_unixtime(unix_timestamp('2021-09-23','yyyy-mm-dd'),'yyyymmdd') as date
-- 方法二
select concat(substr('2021-09-23',1,4),'-',substr('2021-09-23',6,2),'-',substr('2021-09-23',-2)) date
-- 方法三
select regexp_replace('2021-09-23','-','') as date
-- 方法四 lpad 左补0操作
select concat(year('2021-09-23'),lpad(month('2021-09-23'),2,0),day('2021-09-23'))
-- 带时分秒
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');
select current_timestamp(); -- 精确到毫秒
-- 只取日期
select current_date()
网友评论