dongtan6695 2018-05-12 05:31
浏览 256
已采纳

时间和日期条件逻辑语句MySQL

I am trying to create a logic where I SELECT from my database only rows that have not expired yet. So anything that is greater than NOW() will now show up.

Here is a modified version of a code:

include_once('Database.php');

try {
    $stmt = $conn->prepare("SELECT col1, col2, col3, 
        format_time FROM table WHERE format_time > NOW()");
    $stmt->execute();

} catch (PDOException $e) {
    echo $e->getMessage();

My format_time data is saved as TIMESTAMP in format of 2018-05-13 23:30:00 (YYYY-MM-DD HH:MM:SS).

For some reason I am still retrieveing my data even after the expire date.

  • 写回答

1条回答 默认 最新

  • donglu9825 2018-05-13 06:09
    关注

    Well here what I've done. I went in phpMyAdmin and dropped the event_table. And then I recreated the data again, putting the same exact information. Then the query started running normal again, and meeting the conditions. Now this might be a minor bug, and I am too unsure how to replicate this bug again. However everything is working the way I expect.

    For those who are going to view the post in the future, you might not want to make your data disappear immediately, so I added additional operation:

    SELECT col1, col2, col3, format_time FROM event_table WHERE format_time > DATE_SUB(NOW(), INTERVAL 1 HOUR) ORDER BY format_time ASC

    This query will ensure that the data will only be removed after an hour, when the condition is met.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改