[英]Calculation of date & time and echo in PHP MySQL
I am trying to echo some text if the difference between datetime from MySQL and the current datetime is more than sixty seconds. 如果MySQL的日期时间与当前日期时间之间的差异超过六十秒,则尝试回显一些文本。
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
MySQL中设置的日期和时间是
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. time()
为您提供Unix格式(如1505622974
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']; //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";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.