Do I want to show the birthday boy two days before or after the event?

Asked

Viewed 128 times

1

I have a consultation that shows on the system Dashboard the birthdays of the week, all who make birthdays between Sunday and Saturday are displayed on the screen, but it is very annoying to watch until Friday who made birthday on Monday. Would have the possibility to change the query that I am using to show the same just 2 days before or even 2 days after?

My Query

SELECT * FROM tbl_usuarios WHERE (WEEK(DATE_ADD(Aniversario, INTERVAL (YEAR(now()) - YEAR(Aniversario)) YEAR)) = WEEK(now()))

I made a function in php but it got too big, so I wanted to do in the sql query itself.

1 answer

1


This is Momesso, blz?

See on fiddle. Switch down the date '2019-01-05' for now().

select q.id, q.niver
from (select id, 
             date(concat(year(now()), '/', month(aniversario), '/', day(aniversario))) as niver
      from tbl_Usuarios) as q
where q.niver between date_add(date '2019-01-05', interval -2 day) and
                      date_add(date '2019-01-05', interval +2 day);
  • This is Marcelao Show.... Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.