我尝试从数天开始获得年数,月数和天数。我试过这个:
SELECT enddate,startdate,extract(month from enddate)-extract(month from startdate)
FROM workexpdeails ;
答案 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