mysql 时间差,返回年月日格式

select if( month('2014-10-13')-month('2010-09-21')>0,
concat(year('2014-10-13')-year('2010-09-21'),'年',month('2014-10-13')-month('2010-09-21'),'月',
 CASE WHEN day('2014-10-13')>day('2010-09-21') THEN day('2014-10-13')-day('2010-09-21') ELSE  day('2014-10-13')+30-day('2010-09-21') END ,'天'),
concat(year('2014-10-13')-year('2010-09-21')-1,'年',month('2014-10-13')-month('2010-09-21')+12,'月',
 CASE WHEN day('2014-10-13')>day('2010-09-21') THEN day('2014-10-13')-day('2010-09-21') ELSE  day('2014-10-13')+30-day('2010-09-21') END ,'天')) as r

你可能感兴趣的:(MYSQL)