当结束时间是24小时时,mysql timediff没有正确的输出 [英] mysql timediff no proper output when endtime is 24hrs

查看:265
本文介绍了当结束时间是24小时时,mysql timediff没有正确的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据类型时间来计算所花费的时间。对于计算,我使用 TIMEDIFF(结束时间,开始时间)



查询



  SELECT TIMEDIFF '00:26:08','21:58:18')FROM students_session WHERE id ='#'

我没有得到正确的o / p,它是 02:27:50 。相反,我得到 -21:32:10 ,这是错误的。



如何纠正这个? >

解决方案

问题是知道'00:26:08' / code>在'21:58:18'之后(早上),但MySQL不知道,因此从MySQL的角度来看,结果是正确的。



您需要提供日期部分,其中 end_date 将在第二天下降,或者您需要在 end_date 中添加24小时(1天)。这些将告诉MySQL, end_date 大于 start_date ,您将获得期望的结果。

  SELECT TIMEDIFF(timeadd('00:26:08','24:00:00'),'21:58:18' )from students_session where id ='#'


I'm using datatype time to calculate the class taken timings. For calculation I use TIMEDIFF(endtime,starttime).

Query

SELECT TIMEDIFF('00:26:08','21:58:18') FROM students_session WHERE id='#'

I'm not getting the proper o/p which is 02:27:50. Instead I get -21:32:10, which is wrong.

How to rectify this?

解决方案

The issue is that you know that '00:26:08' is after '21:58:18' (following morning), but MySQL is not aware, thus the result is correct from MySQL point of view.

You either need to provide a date part, where the end_date falls to the next day, or you need to add 24 hours (1 day) to the end_date. These will tell MySQL that the end_date is greater than the start_date and you will get the results you expect.

SELECT TIMEDIFF(timeadd('00:26:08','24:00:00'),'21:58:18') from students_session where id='#'

这篇关于当结束时间是24小时时,mysql timediff没有正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆