如何将天数转换为年,月和日的格式

时间:2011-12-22 11:07:43

标签: mysql

我尝试从数天开始获得年数,月数和天数。我试过这个:

SELECT enddate,startdate,extract(month from enddate)-extract(month from startdate)
  FROM workexpdeails ;

1 个答案:

答案 0 :(得分:0)

SELECT 
  enddate
  ,startdate
  ,(YEAR(enddate)*12+MONTH(enddate)) - (YEAR(startdate)*12+MONTH(startdate)) 
   as diffmonths 
  ,DATEDIFF(enddate, startdate) as diffdays
FROM workexpdeails ;

请参阅:http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html