我正在尝试使用 php 减去两个日期。Dateone 存储在数据库中,而 datetwo 是当前日期。现在,我有这个奇怪的场景: Dateone 是 23-03-13 日期二是 02-04-13
使用不同的减法方法,给出不同的结果。
方法一 - 返回 -21
$sqldate ="SELECT exam_date FROM exam_table";
$fetchdate = mysql_query($sqldate);
$rowdate = mysql_fetch_array($fetchdate);
//Fetch the date stored in the database
$dateone = $rowdate['exam_date'];
//Calculate the current date today
$datetwo =date('d-m-y');
//Calculate the diff between the two dates
$datediff = $datetwo-$dateone;
在这种情况下,$datediff 返回 -21
方法二 - 返回 -7639
$sqldate ="SELECT exam_date FROM exam_table";
$fetchdate = mysql_query($sqldate);
$rowdate = mysql_fetch_array($fetchdate);
//Fetch the date stored in the database
$dateone = $rowdate['exam_date'];
//Calculate the current date
$datetwo =date('d-m-y');
//Calculate the diff between the two dates
$datetime1 = strtotime("$dateone");
$datetime2 = strtotime("$datetwo");
//seconds between the two times
$secs = $datetime2 - $datetime1;
$days = $secs / 86400;
在这种情况下,$days 返回 -7639