Anonymous Anonymous - 1 year ago 107
MySQL Question

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 -

then I want the result to be displayed as
1.11 years
. how can I do that ?

Right now I'm using
which gives me value in years.

Please help.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download