Sridhar
Sridhar

Reputation: 2228

SQL: Get data between the current date and current date +15 days

In My application have to find upcoming birthday members , so I have to find the birthday between current date and current date +15 days.

I tried this query

Select name from tname 
where dayofyear(birthday)-dayofyear(now()) between 0 and 15

this query is not working when the current date reaches end of year

Please provide me the correct way.

Upvotes: 1

Views: 751

Answers (2)

Devart
Devart

Reputation: 121902

Try this query -

SELECT
  name
FROM
  tname
WHERE
  birthday + INTERVAL YEAR(CURDATE()) - YEAR(birthday) YEAR
    BETWEEN (CURDATE()) AND CURDATE() + INTERVAL 15 DAY;

Upvotes: 1

Aravintha Bashyam.c
Aravintha Bashyam.c

Reputation: 110

select * 
from tname 
where DATEDIFF(MAKEDATE(YEAR(now()),DAYOFYEAR(birthday)),now()) BETWEEN 0 and 15

this may help you..,this will the short method.

Upvotes: 0

Related Questions