mysql——date_format(),str_to_date()函数

发布时间 2023-04-12 14:53:40作者: hushuer

date_format():

类似python中的strftime: 将给定格式的日期时间对象转换为字符串。日期时间对象=>字符串,控制输出格式

select date_format(datetime的字段,‘%Y-%m-%d’)

括号中前面是你要格式化的字段,后面是具体要格式化成什么样式。

 

str_to_date():

类似python中的strptime:将字符串解析为给定格式的日期时间对象。字符串=>日期时间对象,解析字符串

select str_to_date('2022-02-02','%Y-%m-%d')

后面的格式,要与前面字符串的格式严格对齐

 

参考:

https://www.cnblogs.com/hushuer/p/17021674.html

https://mp.weixin.qq.com/s?__biz=MzI2NzM1OTM4OA==&mid=2247498800&idx=1&sn=cf023a4c36a593ae0d0255c1b39bd6db&chksm=ea82b9c3ddf530d5e179b677113be7e2b8c29b6031985da17df19118d50db46d95e658771c75&scene=27