如何获取 MYSQL 中两个日期时间之间的差异?
我正在尝试此操作
SELECT DATEDIFF(second,log.start_time,log.end_time)
as seconds
from log
where log.log_id = "some crazy UUID";
,但收到错误,因为 DATEDIFF()
不接受像第二这样的格式化程序 expr。
所以我尝试了,
SELECT second(DATEDIFF(second,log.start_time,log.end_time))
as seconds
from log
where log.log_id = "some crazy UUID";
但这也不适用于格式化。
I'm trying this
SELECT DATEDIFF(second,log.start_time,log.end_time)
as seconds
from log
where log.log_id = "some crazy UUID";
but I get an error because DATEDIFF()
accepts no formatter expr like second.
So I tried,
SELECT second(DATEDIFF(second,log.start_time,log.end_time))
as seconds
from log
where log.log_id = "some crazy UUID";
But that doesn't work for formatting either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为你打算使用
TIMESTAMPDIFF()
而不是DATEDIFF()
:I think you meant to use
TIMESTAMPDIFF()
instead ofDATEDIFF()
:试试这个
Try this
DATEDIFF 仅接受两个参数,而您在此处传递三个参数。
它是如何工作的,并且它只返回黑白日期的差异,不包括时间。
http://dev.mysql.com/doc /refman/5.1/en/date-and-time-functions.html
DATEDIFF accept only two parameters and you are passing three parameters here.
How it works and also it returns only the difference b/w dates not including time.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
DATEDIFF()
返回差异天数。使用
TIMEDIFF()
或使用TO_SECONDS()
转换两个时间戳并获取它们的差异:DATEDIFF()
returns days of difference.Use
TIMEDIFF()
or convert both timestamps withTO_SECONDS()
) and get their difference:DATEDIFF :
来自 msdn,它返回指定开始日期和结束日期之间跨越的指定日期部分边界的计数(有符号整数)。
DATEDIFF()
函数返回两个日期之间的时间。语法:
您应该使用
TIMEDIFF()
或TIMESTAMPDIFF()
函数。只需将
TIMESTAMPDIFF()
函数替换为DATEFDIFF()
DATEDIFF :
From the msdn, it returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate. The
DATEDIFF()
function returns the time between two dates.Syntax :
You should use
TIMEDIFF()
orTIMESTAMPDIFF()
function.Just replace
TIMESTAMPDIFF()
function withDATEFDIFF()