In a table with persons and their birthdays, the ones whose birthday is in less than 7 days need to be displayed.

I found some answers on the Internet but they all are at least 5 years ago with DATEDIFF that has 3 arguments instead of 2 and that doesn't help me.

I've just begun to work with Mysql and Workbench so, please, just change my simple syntax.

MONTH(ls_bday) = 1 OR (ls_bday) = 2
and dayofmonth(ls_bday) < dayofmonth(current_time()+8)

or to include something in:

SELECT DATEDIFF(ls_bday, current_date())
from list

Thank you in advance.

  • "with DATEDIFF that has 3 arguments instead of 2" Have you searched solution for the right dbms??? Even if the solution is not for MySQL, how hard can it be to convert SQL Server DATEDIFF() to MySQL DATEDIFF()? It's part of programmer's job to figure things out. – Eric Jan 15 at 19:02
  • Not sure how is your research skill, but here's the difference. SQL Server: docs.microsoft.com/en-us/sql/t-sql/functions/… MySQL: dev.mysql.com/doc/refman/8.0/en/… – Eric Jan 15 at 19:05
  • @Eric yes, I researched that, converted it, and saw those of your link but still cannot change the syntax to display what it should. – Com Jan 16 at 14:47

Try this

FROM list
| improve this answer | |
  • I am still getting the full table and not only the fields where bday is in less than 7 days...:/ – Com Jan 16 at 14:46
  • @Com Debugging is part of programmer's job. Have you tested what is the result of DATEDIFF(ls_bday, CURRENT_DATE())? – Eric Jan 16 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.