php - 以秒为单位获取两个 MYSQL 日期时间列之间的差异

标签 php mysql database datetime

<分区>

Possible Duplicate:
MYSQL - datetime to seconds

如果我在 mysql 表中有一个 datetime 列,我如何在几秒钟内得到 NOW() 和该列之间的差异?

最佳答案

通过TIMEDIFF你可以得到以秒为单位的差异

    SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));

或者这个

SELECT DATEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01') * 24*60*60;
// result: 86400 the difference in seconds for days.

或:

 SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
 // result: 79259  the difference in seconds with the time.

关于php - 以秒为单位获取两个 MYSQL 日期时间列之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13902579/

相关文章:

php - Laravel - 一般错误 : 1366 Incorrect integer value

c# - 使用 ASPNETDB.MDF 添加到 c# asp.net 中的表

database - 100 万个句子保存在数据库中 - 删除不相关的英语单词

php - 使用PHP确定一个图像在另一个图像中的位置

PHP:如何禁止用户生成的内容中包含 HTML 内容?

php - MySQL/php 字符集疯狂 : which one is correct?

asp.net - 在 asp.net 应用程序中打开/关闭连接的良好做法?

iphone - 我使用 SQLite 管理器创建一个数据库调用 test.sqlite。我可以将 .sqlite 数据库导入到 xcode 吗?

php mongodb 发现不工作

php - 删除页面不起作用