I am trying to echo some text if the difference between datetime from MySQL and the current datetime is more than sixty seconds.
But my code is showing every time.
<?php
session_start();
require_once 'class.php';
$reg = new USER();
$stmt = $reg->runQuery("SELECT * FROM validation WHERE vid=2");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$usrmail = $row['vdate'];
$login_session_durations = 60;
if(((time() - $usrmail) > $login_session_durations)) {
echo "Ok";
}
?>
Date & Time set in MySQL is 2017-09-17 06:53:39.000000
time()
gives you the output in Unix format like 1505622974
so to compare we need both the times variable in the same format.
<?php
session_start();
require_once 'class.php';
$reg = new USER();
$stmt = $reg->runQuery("SELECT * FROM validation WHERE vid=2");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$usrmail = $row['vdate']; //The format for vdate: 2017-09-17 06:53:39.000000
$login_session_durations = 60; //In Seconds
if(((time() - strtotime($usrmail)) > $login_session_durations)) {
echo "Ok";
}
?>
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.