简体   繁体   中英

How to check past date should not be past from current date in PHP? in this second condition not working

My code is here,I am not able to perfect. when press submit button it check old date correct.. and shows "date must be in future" it correct. and whenever i put future date.. that time not show second alert instead it showing first.

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;
}

Try below example to fine date passed or not

$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';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM