CREATE TABLE `dt` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '记录ID ',
`Times` datetime DEFAULT NULL COMMENT '创建时间 ',
PRIMARY KEY (`ID`)
`ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '记录ID ',
`Times` datetime DEFAULT NULL COMMENT '创建时间 ',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=144 DEFAULT CHARSET=utf8;
insert into `dt` values(1,'2015-03-24 13:38:11');
DATE_SUB减
SELECT DATE_SUB(Times,INTERVAL 1 DAY) AS DiffDate FROM dt;
输出结果为:2015-03-23 13:38:11
DATE_ADD加
SELECT DATE_ADD(Times,INTERVAL 1 DAY) AS timeframe FROM dt;
输出结果为:2015-03-25 13:38:11
格式化日期
date_format(invest.investTime,_utf8'%Y-%m-%d %T')
转换为天数,可以两个时间相减得到天数
to_days(时间1) -to_days(时间2)