-2

Birthday alert before 1 week. How to check current date with birthday date? My database is MySQL

<?php

$birthday_query = $link->query("SELECT u.u_username, u.u_birthday
FROM ".TBL_PREFIX."users u
WHERE u.u_banned = '0'
AND u_confirmed = '1'
AND u_birthday LIKE '" . $link->asf_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%'
ORDER BY u_username ASC");

?>

Its not working.

4

2 回答 2

1

使用 mysql NOW&+ INTERVAL 7 DAY获取从现在起 1 周后的日期,DATE_FORMAT用于指定 u_birthday 的格式

尝试这个...

$birthday_query = $link->query("SELECT u.u_username, u.u_birthday
                                FROM ".TBL_PREFIX."users u
                                WHERE u.u_banned = '0'
                                        AND u_confirmed = '1'
                                        AND u_birthday = DATE_FORMAT(NOW(), '%Y-%m-%d') + INTERVAL 7 DAY
                                      ORDER BY u_username ASC");
于 2012-12-21T09:47:28.117 回答
1

尝试这个:

"SELECT * 
FROM your_tbl 
WHERE (DATE_ADD(YOUR_DATE, INTERVAL -7 DAY)) = " DATE(); //Your php current date
于 2012-12-21T09:52:10.210 回答