我正在设置一个 Cron,我想在与当天匹配的记录上执行各种功能
我的users
桌子:
Username registration_date expiration_date
behz4d 2012-01-19 21:55:44 2013-01-23 11:15:24
test 2012-05-24 17:42:13 2013-04-12 17:23:19
...
现在我想获取他们的用户,expiration_date
我TODAY
只需查询表,将他们expiration_date
放入数组中,然后将该日期与今天的日期进行比较,例如:
$current_date = date("Y-m-d");
$query = mysql_query("SELECT username FROM users");
while($row = mysql_fetch_array($query)){
$users_array[] = $row['username'] . "->" . substr($row['expiration_date'], 0, 10);// since I don't care about the exact time, I need to get the users who their expiration DAY is today
}
foreach($users_array $username as $expiration_date){
if($expiration_date == $current_date)
$my_target_users[] = $username;
}
但这似乎有点奇怪,我的意思是应该有另一种方法......
反正有什么我可以说的expiration_date = TODAY
吗?
有人可以帮我解决这个问题吗?提前致谢
更新:
如何让用户的到期日是从今天起 3 天?我想给他们发送一封电子邮件,让他们知道他们的帐户将在 3 天后过期......我应该这样做:
... WHERE expiration_date >= CURRENT_DATE AND expiration_date < CURRENT_DATE + INTERVAL 3 DAYS
!?