我的数据库表中有两个字段departureDateTime和arrivalDateTime
以及类似的值
departureDateTime=03/18/2012 1:05 PM
arrivalDateTime=03/18/2012 3:15 PM
我的表中有数百条记录。
我需要根据这两个时间的持续时间来排序和显示。我知道计算两个日期的持续时间
Duration=(strtotime($arrivalDateTime') - strtotime($departureDateTime))/3600
但是我如何编写一个 mysql 查询来排序并显示数据库中的这 100 条记录
有谁知道吗?
谢谢
最佳答案
将您的出发日期时间更改为 DATETIME,而不是 varchar 或您当前使用的任何值。然后你会使用这样的东西:
SELECT other, stuff, TIMEDIFF(departureDateTime, arrivalDateTime) as theDifference FROM myTable ORDER BY theDifference ASC LIMIT 0, 100
关于php - php根据日期差异显示数据库中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9732467/