我的代码在这里,我无法完善。当按下提交按钮时,它检查旧日期是否正确..并显示"日期必须在将来"它是正确的。每当我把未来日期...那个时间没有显示第二个警报而不是它首先显示。
if(isset($_POST['update']))
{
$pdata["card"] = $_POST['smcard'];
$pdata["expiry_date"] = date("Y-m-d" strtotime($_POST['smexdate']));
$dateone = $pdata["expiry_date"];
$nowdate = new DateTime();
if ($dateone < $nowdate)
{
echo "<script>";
echo "alert('date must be in future');";
echo "</script>";
}
elseif ($dateone > $nowdate)
{
echo "<script>";
echo "alert('Okay Good, Your date is in future');";
echo "</script>";
}
update_data('smartcard_data', $pdata, 'promotion_id='.$_REQUEST['promotion_id']);
exit;
}
答案 0 :(得分:0)
请尝试以下示例,以确认日期是否通过
$dtA = new DateTime('05/14/2010 3:00PM');
$dtB = new DateTime('05/14/2010 4:00PM');
if ( $dtA > $dtB ) {
echo 'dtA > dtB';
}
else {
echo 'dtA <= dtB';
}