php - 如何获得空日期时间戳和其他确定的持续时间?
问题描述
我正在编码以计算空时间戳日期和另一个非空日期之间的持续时间,请帮助我。
我想计算此持续时间以设置确认代码在论坛参与者回来太晚或超过 2 天没有回来时过期作为最大延迟
此代码工作正常,除非返回日期为空:
$date_participation= strtotime($row['date_participation']);
$date_come_back= strtotime($row['date_come_back']);
$expiration_delay = 2;
$days = $expiration_delay * 86400;
echo "<br> duration in seconds is: " . $date_come_back-
$date_participation;
if (($date_come_back- $date_participation) >= $days){
$sql_set_expired = "UPDATE `winners` SET `confirmation_status` = 'expired' WHERE id_recharge_winner ='$i'";
$set_expired_result = mysqli_query($conn, $sql_set_expired);
}
the `$i` is the participant's row in table winners
解决方案
这就是我在不担心是否有空日期的情况下导致我的问题的方式:我创建了一个函数 Difference_between_timestampdate() ,而不是我指定的一天,例如到期持续时间。它工作正常,感谢帮助我的人。
function Difference_between_timestampdate($first_date, $last_date){
$first_date = strtotime($first_date );
$last_date = strtotime($last_date);
$days = $expiration_delay * 82800;
if(empty($last_date)){
$duration = time() - $first_date;
}else{
$duration = $last_date - $first_date;
}
return $duration;
}
$date_participation = $row['date_participation'];
$date_come_back = $row['date_come_back'];
$expiration_delay = 1; //One day
if ((Difference_between_timestampdate($date_participation, $date_come_back)/82800 )
>= $expiration_delay){echo 'Expired duration';}else{echo 'Valid duration';}
推荐阅读
- typescript - TypeScript 无法分配给可选属性“不可分配给未定义的类型”
- javascript - 如何在 React Bootstrap 中使这些卡的底部大小相同
- ffmpeg - 并行ffmpeg过滤复杂管道
- rust - 是否有 rust crate ldap3 的示例代码显示使用用户名和密码对 ldaps 进行身份验证(绑定)
- reactjs - redux 工具包 createAsyncThunk 打字稿错误
- visual-studio - Visual Studio 2019 安装 MFC 库?
- android - Android动画不移动文本视图
- c++ - c++中指针与int类型的比较
- android - 消息“错误:资源 android:attr/lStar 未找到”
- sql - SQLite 仅按第一个 WHERE 匹配排序