我有一个名为 ending
的时间戳字段。我想计算从现在到那天之间的时间。
这是我正在尝试的,但结果只是说blob
select item_id, CONCAT(
FLOOR(HOUR(TIMEDIFF(now(), ending)) / 24), ' days, ',
MOD(HOUR(TIMEDIFF(now(), ending)), 24), ' hours, ',
MINUTE(TIMEDIFF(now(), ending)), ' minutes')
AS TimeDiff from items where item_id=39
或者我应该使用 PHP 来代替?它们都在页面上广泛使用...我正在假设,因为我已经在执行查询,然后将其包含在其中,这比另一个 PHP 调用更有效 - 但是,我可能是错的!
更新我做了一个fiddle为此,它工作得很好,那么为什么我在 MySQL Workbench 中的结果会显示 blob
?
这是表格的解释:
item_id int(11) NO PRI auto_increment
user_id int(11) YES
title varchar(128) YES
price decimal(10,2) YES
category int(11) YES
cat_parent int(11) YES
description varchar(1024) YES
item_condition int(11) YES
delivery varchar(45) YES
ending timestamp YES
postcode varchar(12) YES
latitude float(10,6) YES
longitude float(10,6) YES
dateadded timestamp YES CURRENT_TIMESTAMP
最佳答案
将 SELECT 放在查询的开头吗?
SELECT CONCAT(
FLOOR(HOUR(TIMEDIFF(now(), '2012-08-02 11:20')) / 24), ' days, ',
MOD(HOUR(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')), 24), ' hours, ',
MINUTE(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')), ' minutes, ',
SECOND(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')), ' seconds')
AS TimeDiff
返回 34天22小时36分0秒
关于php - 计算 now() 和时间戳字段之间的时间 - MySQL 还是 PHP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20702788/