Get Birthday From Timestamp Field

Submitted by:Andery Smith

Date added:12 August, 2012

Category:MySQL

Demonstrates to select all the Birthdays that will occur as of today, 15 days

Tags: get birthday , timestamp field

Code Snippet:

SELECT SQL_CACHE /*??? prefira 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