0

I'm having issues trying to create a MySQL function to calculate the age trough a date given, I know I may get told to use a procedure to do it, but am forced to do it in a function.

PS ik there's (SELECT DATEDIFF(YEAR,DATE()) CURDATE())) but can't use it in a function so.

Any ideas of how should I do it?

Best regards, Engineer

Engineer
  • 59
  • 4
  • Select into a variable then return the variable - it's how functions work.. Please add the code you have so far. – P.Salmon May 14 '20 at 12:53
  • DATEDIFF() does not accept unit type and calculates the difference in days strictly. Use [TIMESTAMPDIFF()](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timestampdiff) with *unit = `YEAR`*. – Akina May 14 '20 at 13:04
  • 1
    Does this answer your question? [Calculate Age in MySQL (InnoDb)](https://stackoverflow.com/questions/5773405/calculate-age-in-mysql-innodb) – rajah9 May 14 '20 at 13:27

0 Answers0