Home > Software engineering >  Ms acccess SQL Query to get Birthday between two dates
Ms acccess SQL Query to get Birthday between two dates

Time:11-28

Ms access SQL Query to get Birthday between two dates

I want to know whose birthday comes between given date. For example FromDate :-27-11-2021 ToDate:- 02-12-2021 I want to get all birthdays between FromDate and ToDate

What I tried:-

 SELECT * FROM tblMembers WHERE (Month(DOB) = 11 AND Day(DOB) >= 27) AND (Month(DOB) = 12 AND Day(DOB) <= 02 and Year(DOB)>1753)  OR (Month(DOB) > 11 AND Month(DOB) < 12 and Year(DOB)>1753) and status='Active' Order by Month(dob), Day(dob)

When From month and To month is same above query is correct but the different month it's not showing any data.

CodePudding user response:

you can use between operator

  SELECT *
  FROM tblMembers 
  WHERE dob BETWEEN fromDate AND toDate AND status = 'Active'
  ORDER BY dob

CodePudding user response:

SELECT * FROM tblMembers WHERE ((DOB) >#27-11-2021# AND (DOB)<#02-12-2021#) and status='Active' Order by Month(dob), Day(dob)

  • Related