0

我有一个约会表,我想向用户显示他所做的所有约会都高于当前日期,以便他可以取消它们......我有这个查询......

$result = mysql_query("SELECT id,date,start,end FROM jos_jxtc_appbook_appointments WHERE userident='$idusera' AND CONCAT(date,' ',start)>NOW()");
while($row = mysql_fetch_assoc($result))
{

echo '<div class="record" id="record-',$row['id'],'">
    <a href="?delete=',$row['id'],'" class="delete">Delete</a>
    <strong>',$row['date'], $row['start'], $row['end'],'</strong>
  </div>';

}

并且这仍然显示日期低于当前日期......可能是时区错误或类似的东西?

这是我的桌子...

   date     duration    start     end
2013-02-28  01:00:00  12:00:00  13:00:00
2013-02-28  01:00:00  03:00:00  04:00:00
2013-02-27  01:00:00  21:00:00  22:00:00
2013-02-27  01:00:00  20:00:00  21:00:00
2013-02-28  01:00:00  20:00:00  21:00:00
2013-02-28  01:00:00  01:00:00  02:00:00
2013-02-28  01:00:00  09:00:00  10:00:00
2013-02-28  01:00:00  02:00:00  03:00:00
2013-03-01  01:00:00  00:00:00  01:00:00
2013-02-28  01:00:00  21:00:00  22:00:00
2013-02-28  01:00:00  22:00:00  23:00:00
2013-03-01  01:00:00  02:00:00  03:00:00

我从我的回声中得到这个......

Delete 2013-02-28  12:00:00  13:00:00
Delete 2013-02-28  20:00:00  21:00:00
Delete 2013-03-01  00:00:00  01:00:00
Delete 2013-02-28  21:00:00  22:00:00
Delete 2013-02-28  22:00:00  23:00:00
Delete 2013-03-01  02:00:00  03:00:00   

因此,如果当前时间是现在的 2013-02-28 15:25:00,则不应显示低于 2013-02-28 12:00:00 13:00:00 的日期。

4

2 回答 2

0

您需要 STR_TO_DATE() 函数将字符串转换为有效的日期值。

$result = mysql_query("SELECT id,date,start,end FROM jos_jxtc_appbook_appointments WHERE userident='$idusera' AND STR_TO_DATE(CONCAT(date,' ',start))>NOW()");
于 2013-02-28T14:35:16.280 回答
0

我假设date是一个Date类型,两者start都是end类型Char列。您应该为您的和列使用一个DateTime类型,这样您就不需要做任何连接。现在你可以做。startendstart > NOW()

于 2013-02-28T14:28:10.823 回答