Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

MySQL str_to_date 如果字符串中没有年 怎么补上?

格式完整的字符串时间可以通过str_to_date转换为标准时间。
但是这种没有“年份”的数据,转换后年份为0000:
image.png
image.png

这种怎么在转换后,补上2020?

已解决:
select CONCAT(2020,RIGHT(str_to_date(chengjiao,'%m-%d'),6)) as sell_time,sell from table_name ORDER BY sell_time


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

已解决:
select CONCAT(2020,RIGHT(str_to_date(chengjiao,'%m-%d'),6)) as sell_time,sell from table_name ORDER BY sell_time


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...