Get Birthday From Timestamp Field

Submitted by:Andery Smith

Date added:12 July, 2012

Category:MySQL

Select all the Birthdays that will occur as of today, 15 days

Tags: get birthday , timestamp field

Code Snippet:

SELECT SQL_CACHE /*??? prefer memcache, APC, etc..*/
name,
birthday,
YEAR(birthday),
YEAR(NOW()),
(YEAR(NOW()) - YEAR(birthday)),
DATE_ADD(birthday, INTERVAL (YEAR(NOW()) - YEAR(birthday)) YEAR),
DATE_ADD(NOW(), INTERVAL 15 DAY )
FROM customers
WHERE
DATE_ADD(birthday, INTERVAL (YEAR(NOW()) - YEAR(birthday)) YEAR)
BETWEEN
DATE( NOW() )
AND
DATE_ADD(NOW(), INTERVAL 15 DAY )
 
 

Comments