简体   繁体   中英

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.

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.

help me thanks.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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