You want something like this in MySQL ( edited - REALLY WORKING EXAMPLE):
SELECT * FROM `tbl_office_employee` e WHERE FLOOR( ( UNIX_TIMESTAMP( CONCAT( YEAR(CURDATE()) + (DATE_FORMAT(e.birthdate, '%m-%d') < DATE_FORMAT(CURDATE(), '%m-%d')), DATE_FORMAT(e.birthdate, '-%m-%d'))) - UNIX_TIMESTAMP(CURDATE())) / 86400) < 5
The SQL query below does not determine the birthday which is next year (i.e. January 1-5, when it is December 31st), so use the one above ...
SELECT * FROM tbl_office_employee e WHERE UNIX_TIMESTAMP (DATE_FORMAT (e.birthdate, CONCAT (YEAR (CURDATE ()), '-% m-% d'))) BETWEEN UNIX_TIMESTAMP (CURDATE ()) AND UNIX_TIMESTD (CATE) INTERVAL 5 DAY))
I had to use UNIX_TIMESTAMP due to daily changes from May 31 to June 5 (5 no more than 31) and change the year to e.birthdate .
This can be done in DQL (Doctrine 1):
Doctrine_Query::create() ->select('e.firtsname') ->from('tbl_office_employee e') ->where('e.date BETWEEN ? AND ?', array($today_date, $date_plus_5_days)) ->getSqlQuery();
which should output basically the same thing.
I donβt think that DATE_ADD is available in DQL out of the box, but there is a chapter in the documents called DQL User Defined Functions, which has an example implementation of the DATE_ADD function for MySQL .
source share