简体   繁体   English

查看SQL中最接近的日期和时间的记录

[英]View Records in sql base on the closest date and time

Please help me view the records based on closest date and time. 请帮助我根据最近的日期和时间查看记录

I can only display the closest DATE , i dont know how to display it with time. 我只能显示最近的DATE ,我不知道如何随着时间显示。

here's my code 这是我的代码

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

the schedule_time is in TimeStamp format in mysql. schedule_time在mysql中为TimeStamp格式。

help me thanks. 帮我谢谢。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM