I am trying to filter the employees records whose birthday falls during last 3 days including today on the basis of birthday_date
column in the tb_Employee
table in MS Access . I know I can get latest 3 days record on the basis of date:
Select * from tb_Employee where ([Date_Column] >= NOW()-3
But in my case in birthday_date
column date is in past year (say 18/1/1975). Please help me to fix this
I might suggest:
select * from tb_employee
where
(dateserial(year(date()),month(birthday_date),day(birthday_date)) between date()-3 and date()) or
(dateserial(year(date())-1,month(birthday_date),day(birthday_date)) between date()-3 and date())
In words, this query is stating:
"Select employees for which their Birthday this year is between the last 3 days and today, or their Birthday last year is between the last 3 days and today"
If you want peoples whose birthdays are in the past three days, here is one method:
where dateserial(year(date()), month(dob), day(dob)) in
(
date(), dateadd("d", -1, date()), dateadd("d", -2, "date"),
dateadd("y", 1, dateadd("d", -1, date())),
dateadd("y", 1, dateadd("d", -2, "date"))
)
The last two handle Dec 30th and Dec 31st.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.