【问题标题】:View Records in sql base on the closest date and time根据最近的日期和时间查看 sql 中的记录
【发布时间】:2017-07-01 02:38:01
【问题描述】:

请帮我查看基于最近日期和时间的记录。

我只能显示最接近的DATE,我不知道如何随时间显示。

这是我的代码

SELECT * FROM tbl_schedules WHERE schedule_time > NOW() 
ORDER BY ABS(DATEDIFF(schedule_time , NOW())) ASC

schedule_time 在 mysql 中是时间戳格式。

帮帮我,谢谢。

【问题讨论】:

    标签: php mysql select timestamp datediff


    【解决方案1】:

    将时间戳转换为数字格式,然后减去它们。

    ORDER BY ABS(UNIX_TIMESTAMP(schedule_time) - UNIX_TIMESTAMP()) ASC
    

    【讨论】:

      猜你喜欢
      • 2021-12-19
      • 2019-03-29
      • 2019-08-26
      • 2013-08-25
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多