I have all users' birthdays stored as a UNIXtimestamp and am wanting to send out e-mails each day to users that have a birthday that day.
I need to make a MySQL query that will get all of the rows that contain a birthday on today's date.
It seems like this should be fairly simple, but maybe I am just overcomplicating it.
Simply use the CURDATE() function to get the current date. The date can be displayed in two different formats: ' YYYY-MM-DD ' if it is used in a string context or YYYYMMDD if it is used in a numeric context. There are two other functions that can be used instead of CURDATE() : CURRENT_DATE and CURRENT_DATE() .
-- Query to find workers, whose birthday is in current week SELECT * FROM @Workers WHERE DATEPART( Week, DATEADD( Year, DATEPART( Year, GETDATE()) - DATEPART( Year, DOB), DOB)) = DATEPART( Week, GETDATE()); The basic idea is the same as in the first query I explained.
MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts.
A person's birthday would be its own data type capturing observed birthday's (Month/Day) - the type of data one can capture but doesn't presuppose making any guesses as to age and the actual year of birth.
You can use the query below if date of birth stored in a table.
Today Birthday :
select * from TABLENAME
where DAY(FIELDNAME) = DAY(CURDATE())
and MONTH(FIELDNAME) = MONTH(CURDATE());
Yesterday Birthday:
select * from TABLENAME
where DAY(FIELDNAME) = DAY(DATE_ADD(CURDATE(), INTERVAL -1 DAY))
and MONTH(FIELDNAME) = MONTH(CURDATE());
Tomorrow Birthday:
select * from TABLENAME
where DAY(FIELDNAME) = DAY(DATE_ADD(CURDATE(), INTERVAL 1 DAY))
and MONTH(FIELDNAME) = MONTH(CURDATE());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With