【问题标题】:seeing if date is less than 24 hours, then if statement depending [duplicate]查看日期是否小于 24 小时,然后 if 语句取决于 [重复]
【发布时间】:2014-04-26 18:41:19
【问题描述】:
    $test = $info['date'] . $info['time'];

    $date = date("Y-m-d H:i:s", strtotime($test));

    if (isset($_SESSION['id']) && $_SESSION['id'] == $_GET['id'])
    {
        if (isset($_GET['BookID']) && is_numeric($_GET['BookID']))
        {
            if ($date >= (time() + 86400)) {
            // current time is 86400 (seconds in 24 hours) or less than stored time

                $sql = "DELETE FROM `tbl_booking` WHERE `BookID`={$BookID}";
                $result = mysqli_query($con, $sql);
                //header("refresh:5;url=dashboard.php");
                echo "Your booking has been cancelled.";
            }
        }
    } else {
        // if id isn't set, or isn't valid, redirect back to view page
        //header("refresh:5;url=dashboard.php");
        echo ("Sorry, there is less than 24 hours left and you cannot cancel.");
    }

对不起,我到处找了这个,我仍然无法理解。

基本上,我正在制作一个允许用户取消但如果他们尝试预订的时间少于 24 小时的预订系统。

目前这似乎拒绝每一个删除,说即使没有还剩不到 24 小时。

【问题讨论】:

  • 我已经在那里问过了,但是当我解决了这个问题时,我的问题已经改变了。问题是没有人真正回复那里了。
  • 您将日期字符串与 unix 时间戳进行比较,您还需要将 $date 转换为 unix 时间戳。
  • 好的,我会调查的,谢谢
  • $info['date']$info['time'] 是否来自数据库?如果是这样,有更简单的方法可以在 SQL 查询中按照您想要的方式获取它。 发布您的查询以获得预订!
  • 至少在示例中您没有定义 $BookID。

标签: php date datetime time


【解决方案1】:

您正在将字符串日期与 unix 时间戳进行比较 - 尝试换行

if ($date >= (time() + 86400)) {

成为

if (strtotime($date) >= (time() + 86400)) {

【讨论】:

  • 这什么也没给我,它完全停止了回声。
猜你喜欢
  • 2014-04-20
  • 2018-04-30
  • 2023-03-19
  • 2012-03-02
  • 2012-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多