用时间戳来计算
SELECT (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP('2015-04-20 15:12:12'))/60
也就是得到两个时间相差的秒数,然后除60得到分种。
不考虑 “天”的因素:select if(month(d2)-month(d1)>0,
concat(year(d2)-year(d1),'年',month(d2)-month(d1),'月'),
concat(year(d2)-year(d1)-1,'年',month(d2)-month(d1)+12,'月')) as r from xxxxx
----------------------------------------------------------------------------------------------------------
例子:
d1='2013-05-13'
d2='2014-07-13'
select if(month('2014-07-13')-month('2013-05-13')>0,
concat(year('2014-07-13')-year('2013-05-13'),'年',month('2014-07-13')-month('2013-05-13'),'月'),
concat(year('2014-07-13')-year('2013-05-13')-1,'年',month('2014-07-13')-month('2013-05-13')+12,'月')) as r
结果:1年2月
=================================================================
d1='2013-05-13'
d2='2014-01-13'
select if(month('2014-01-13')-month('2013-05-13')>0,
concat(year('2014-01-13')-year('2013-05-13'),'年',month('2014-01-13')-month('2013-05-13'),'月'),
concat(year('2014-01-13')-year('2013-05-13')-1,'年',month('2014-01-13')-month('2013-05-13')+12,'月')) as r
结果:0年8月
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)