Awan Awan - 10 months ago 61
MySQL Question

How to calculate difference between two dates in months in MySQL

I have two columns in a MySQL table:

  • DateOfService (datetime)

  • BirthDate (date)

I want to run a MySQL query that will provide date difference between these two fields in months.

How can I do this in a MySQL select query?


Answer Source

This could work:

SELECT 12 * (YEAR(DateOfService) 
              - YEAR(BirthDate)) 
       + (MONTH(DateOfService) 
           - MONTH(BirthDate)) AS months 
FROM table