Use period_diff(), the first value you take from your date or time column, the second value, you can format current date or just supply a year and month!
example.... (return total months)
Code: Select all
period_diff(DATE_FORMAT(DateColumn, '%Y%m'), DATE_FORMAT(CURDATE(),'%Y%m')) AS months
if you want to do it all in your query (year, month), then you will need to use IF(), to test and then do your math operation before returning the value for (year, month), it not that difficult, you can use the same operation as above for years, by just using %Y, removing %m, but you still need to test, so you only return the remaining months that are left from the years! If you don't mind having a decimal single you can just use years and return the years as a decimal value.
pif!