Pankaj Singh
Pankaj Singh

Reputation: 531

Calculate difference between two dates in mysql to show years and months

How can I calculate difference between two dates ( current date and a date stored in database ) in mysql query to give result in years and months.

Suppose there are two dates - 2014-01-01 and 2015-12-28 then I want the result to be displayed as 1.11 years. how can I do that ?

Right now I'm using round(datediff(curdate(),e.joined_date)/365 which gives me value in years.

Please help.

Upvotes: 0

Views: 948

Answers (1)

mynawaz
mynawaz

Reputation: 1594

use TIMESTAMPDIFF like this

SELECT CONCAT(TIMESTAMPDIFF(YEAR, '2014-06-01', '2015-08-01'), '.', TIMESTAMPDIFF(MONTH, '2014-06-01', '2015-08-01')-(TIMESTAMPDIFF(YEAR, '2014-06-01', '2015-08-01') * 12)) AS diff

Upvotes: 3

Related Questions