Finds the date for Easter (Western) given a year.
Sample usage: SELECT easter(YEAR(NOW()));
DELIMITER // CREATE FUNCTION easter(inYear YEAR) RETURNS DATE DETERMINISTIC BEGIN DECLARE a, b, c, d, e, k, m, n, p, q INT; DECLARE easter DATE; SET k = FLOOR(inYear / 100); SET a = MOD(inYear, 19); SET b = MOD(inYear, 4); SET c = MOD(inYear, 7); SET q = FLOOR(k / 4); SET p = FLOOR((13 + 8 * k) / 25); SET m = MOD((15-p+k-q), 30); SET d = MOD((19 * a + m), 30); SET n = MOD((4+k-q), 7); SET e = MOD((2*b+4*c+6*d+n), 7); SET easter = CASE WHEN d + e <= 9 THEN CONCAT_WS('-', inYear, '03', 22 + d + e) WHEN d = 29 AND e = 6 THEN CONCAT_WS('-', inYear, '04-19') WHEN d = 28 AND e = 6 AND a > 10 THEN CONCAT_WS('-', inYear, '04-18') ELSE CONCAT_WS('-', inYear, '04', LPAD(d + e - 9, 2, 0)) END; RETURN easter; END // DELIMITER ;