0

The title says it all.. I am not sure what is wrong with my code.. But it didn't go well as i want to

<?php
//test this
$query = odbc_exec($conn, "SELECT * FROM changepass_req WHERE reqid = 1");
$reqdate = odbc_result($query, 'req_date');
$reqdatex = strtotime($reqdate);
$timenow = date("Y-m-d H:i:s");
    $timenowx = strtotime($timenow);

    if($timenowx <= $reqdatex + 86400) {
    //Less than 24 hours
    echo'Go a head, its not a day passed yet';
    }
    else {
    //More than 24 hours
echo'Sorry, this request is expired!';
    }

?>

The req_date that's in the database is in varchar of datatype. Thanks for the help in advance

EDIT : ALSO the req_date data's are in this format (Y-m-d H:i:s)

EDIT 2 : The return of var_dump($reqdatexx) looked like this in my page : int(1370855859)

EDIT 3 : Here's the concept i want.. If Database time is before OR WITHIN 24 hours of the CURRENT TIME = return true ELSE // if the Database time is BEYOND or PASSED 24 hours of the CURRENT TIME = return false

or , if Database time = 2013 6/8 5:02pm AND Current time = 2013 6/9 5:01pm = return TRUE else //Database time = 2013 g/6 5:02pm AND Current time = 2013 6/9 5:03pm = return FALSE

4

2 に答える 2

1

$reqdatex が現在から +-24 時間以内にあることを確認するには、次の条件を使用します。

<?php

//Mon, 10 Jun 2013 09:17:39 GMT
$reqdatex = 1370855859;
$timenowx = time();

if(($reqdatex <= $timenowx + 86400) and ($reqdatex >= $timenowx - 86400)) {
    //$reqdatex is inside now +- 24 hours interval
    echo'Go ahead';
}
else {
    //not inside the interval
    echo'Sorry';
}
于 2013-06-08T08:34:10.680 に答える