SQL转换日期格式dd-mm-yyyy为yyyy-mm-dd
用到的sql函数:
切割函数
参考:https://blog.csdn.net/ZZQHELLO2018/article/details/110131416
从左开始截取字符串
格式:left(str, length)
如12-08-2019
截取第三个字符,判断是否为-以此来判断这个格式是否为dd-mm-yyyy
select left(‘12-08-2019’,2) as example
判断条件:是否为’-’
where
left(create_time,2)=‘-’
是,那就截取,再拼接
截取:
substring(create_time,0,2) //12-日
substring(create_time,3,2) //08-月
substring(create_time,6,4) //2019-年
拼接:
concat()
update 'user' set create_time=concat(substring(create_time,6,4),'-',substring(create_time,3,2),'-',substring(create_time,0,2))
where left(create_time,2)='-'