首页 > 解决方案 > 如何编写代码以在 2 天后运行

问题描述

您好家人我正在开发一个移动应用程序如果您选择,该应用程序提供多种服务,例如汇款该应用程序必须生成一个唯一的代码,该代码的截止日期为 2 天,我不知道如何帮助我

<?php
include 'my_db.php';
$id=1;
$query = $bdd->prepare("SELECT temps FROM date WHERE ID= '". $id ."'     ");
$query->execute();
while(true)
{   
$start_date = $query->fetch()[0]; //code creation date

$limit_date = $start_date->modify("+2 day"); //code expiration date
if($start_date >=$limit_date)
{
    //your code is invalid
}else 
    {//your code is valid}
}
?>

我以为我会:代码有效或代码无效

标签: php-7.3

解决方案


我找到了解决方案

`<?php
include 'my_db.php';
$id=1;
$dijaa = $bdd->prepare("SELECT temps FROM date WHERE ID= '". $id ."' ");
$dijaa->execute(); 
$code_niane = $dijaa->fetch()[0]; //code creation date
$dst_inf1= strtotime($code_niane); //converting time with strtotime
$dsttr2 = time(); // server date
$sabayke = 2*24*60*60; // code expiration date
if($dsttr2-$dst_inf1==$sabayke){ // if date == 2days
// treatment
}else{
//treatment
}
?>`

推荐阅读