mysql 常用时间函数
1、DATE_FORMAT 日期转成字符串
DATE_FORMAT((FROM_UNIXTIME(addtime,'%%Y-%%m-%%d')),'%%Y%%m')= DATE_FORMAT(CURDATE(),'%%Y%%m')
2、当前日期
CURDATE()
3、当天数据
SELECT TO_DAYS(CURRENT_DATE());
注意别用day取, 不然会有坑!
4、当周数据
YEARWEEK(CURRENT_DATE())
同样不要用week不然也会有坑!
5、当月数据
1)select EXTRACT(YEAR_MONTH from CURRENT_DATE());
2)select count(*) as num from jmgo_users where WEEK(FROM_UNIXTIME(addtime,'%%Y-%%m-%%d'))= WEEK('2016-09-01')and YEAR(FROM_UNIXTIME(addtime,'%%Y-%%m-%%d'))= YEAR('2016-09-01');
6、当年数据
YEAR(CURRENT_DATE())