我有一个名为 notify 的表,其中 (seeker,donor, date) 列
是类型 (datetime) 的日期列,它存储以下格式 YYYY-MM-DD HH:MM:SS
我正在尝试选择 1 条记录最新日期从通知表中,然后将日期与当前日期进行比较并计算两个日期之间的天数..
<?php
session_start();
$email = $_GET['email'];
date_default_timezone_set('Asia/Riyadh');
$time = date("Y-m-d H:i:s");
$note = "SELECT * FROM notify WHERE seeker='".$_SESSION['email']."'AND donor='".$email."' ORDER_BY `date` DESC LIMIT 1";
$st = $conn->prepare($note);
$st->execute();
if($found = $st->fetch(PDO::FETCH_ASSOC)){
$now = $time;
$old_date = strtotime($found['date']);
$dateif = $now - $old_date;
if(floor($dateif/(60*60*24)) >= 7){
echo "the difference between tow dates is 7 days or more";
} else { echo "difference between tow dates is less than 7 days";}
}
?>
代码不工作!
我的通知表中只有一条记录,日期为 2013-04-22 09:15:47