How to get the difference in years from two different dates?
Here’s the expression that also caters for leap years: YEAR(date1) – YEAR(date2) – (DATE_FORMAT(date1, ‘%m%d’) < DATE_FORMAT(date2, ‘%m%d’)) This works because the expression (DATE_FORMAT(date1, ‘%m%d’) < DATE_FORMAT(date2, ‘%m%d’)) is true if date1 is “earlier in the year” than date2 and because in mysql, true = 1 and false = 0, so the adjustment is simply … Read more