我有以下代码,用于计算每月发送的邮件数。这可以改为每日吗?我尝试了一些改动,但他们没有成功。有什么建议?非常感谢你提前!我是PHP / MySQL的新手。另外,我知道当前的MySQL查询已被弃用!:
$vmYear = date("Y");
$vmMonth = date("m");
$vmfromdate = mktime(0,0,0,$vmMonth,"1",$vmYear);
$vmtodate = mktime(0,0,0,$vmMonth,"31",$vmYear);
$verifmessagespermonth = mysql_query("SELECT ID FROM messages WHERE msg_from = '$session_memberid' AND ( time BETWEEN '$vmfromdate' AND '$vmtodate' )");
$nummessagesthismonth = mysql_num_rows($verifmessagespermonth);
} else {
$nummessagesthismonth = 0;
}
答案 0 :(得分:2)
通过添加日期(假设您只存储日期),将int保留在与您相同的结构中。如果您存储日期+时间,则可能需要将0,0,0
从$vmtodate
更改为23,59,59
$vmYear = date("Y");
$vmMonth = date("m");
$vmDay = date("d");
$vmfromdate = mktime(0,0,0,$vmMonth,$vmDay,$vmYear);
$vmtodate = mktime(0,0,0,$vmMonth,$vmDay,$vmYear);
如果你愿意,这仍然允许你制作其他范围
答案 1 :(得分:0)
如果我正确理解了您可以使用此查询的要求:
SELECT
ID
FROM
messages
WHERE
msg_from = '$session_memberid'
AND time BETWEEN
DATE_FORMAT(NOW() , '%Y-%m-%d 00:00:00' )
AND DATE_FORMAT(NOW() , '%Y-%m-%d 23:59:59' )