I need a report that shows me a list of birthdays within the next X days. I wrote a query that works:
I can't figure out how to create the same report using complex expressions, filters, ORM methods, etc. It seems too complex for the abstraction layers, but maybe I don't know how to use it well enough. I am trying to avoid writing raw SQL in a hook. Ideally, the logic would live directly in the report instead of writing any code at all.
dateOfBirth is stored as the real birthday (1999-01-01, for example). Therefore, comparing the year directly won't work.
Code:
SELECT id, DATE_ADD( date_of_birth, INTERVAL TIMESTAMPDIFF(YEAR, DATE_ADD(date_of_birth,INTERVAL 1 DAY), curdate())+1 YEAR ) upcoming_birthday FROM account HAVING upcoming_birthday BETWEEN curdate() AND DATE_ADD(curdate(), INTERVAL 14 DAY)
dateOfBirth is stored as the real birthday (1999-01-01, for example). Therefore, comparing the year directly won't work.
Comment