【MySQL函数】日期篇

1.date_format()函数

date_format(createtime,'%Y')  年

date_format(createtime,'%Y-%m')  年月

date_format(createtime,'%Y-%m-%d')  年月日

这里Y是大写,如果写成小写y,意思就不一样了,

比如:

date_format('2017-07-24','%Y-%m') 结果是2017-07

date_format('2017-07-24','%y-%m') 结果是17-07

原文地址:https://www.cnblogs.com/xphdbky/p/7131315.html