gpt4 book ai didi

php - 如果当前日期和时间大于 Mysql 中存储的日期和时间,则回显一些文本

转载 作者:行者123 更新时间:2023-11-29 18:23:17 24 4
gpt4 key购买 nike

如果当前时间IST超过存储在Mysql中的时间,我正在尝试回显 PHP中的一些文本

存储时间:2017-09-24 16:36:15

当前时间(IST):2017-09-24 16:46:15

我尝试过:

<?php
require_once 'vclass.php';
require_once 'message.php';


$vreg = new Validation();

$stmt = $vreg->runQuery("SELECT * FROM validation WHERE vid=1");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$vusrmaile = $row['svdate'];
$vusrmail = $row['vdate'];
date_default_timezone_set('Asia/Calcutta');
$date = date('Y-m-d h:i:s ', time());

if($date > $vusrmail){
$msg = "
<div class='alert alert-error'>

<strong><center>Process</center></strong>
</div>
";

}
?>

从上面的代码中,我没有得到预期的结果。

最佳答案

您可以将 MySQL 数据库中的时间戳转换为 Unix Time然后与当前时间(以 Unix 时间表示)进行比较:

<?php
require_once 'vclass.php';
require_once 'message.php';


$vreg = new Validation();

$stmt = $vreg->runQuery("SELECT * FROM validation WHERE vid=1");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$vusrmaile = $row['svdate'];
$vusrmail = strtotime($row['vdate']); // Convert MySQL datetime string to Unix Time (this will depend on current timezone)
$date = time(); // Current Unix time (this is independent of timezone)

if($date > $vusrmail){
$msg = "
<div class='alert alert-error'>

<strong><center>Process</center></strong>
</div>
";

}
?>

关于php - 如果当前日期和时间大于 Mysql 中存储的日期和时间,则回显一些文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46389489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com