Substraction between two MySQL's time variable

2019-09-12 00:04发布

I show my problem:

I have two variables that contain the TIME variable from an MySQL database:

$row[0] //it contains for instance 16:30:00
$row[1] //it contains for instance 18:00:00

How do I find the term that is derived from their subtraction?

As they are already time variables I tried to do a subtraction directly with these values ​​but I get integer values ​​rounded down.

I tried existing questions but none foresaw a time in the format HH: MM: SS.

Thank you.

标签: php mysql time
3条回答
来,给爷笑一个
2楼-- · 2019-09-12 00:16

try to use

$query = select TIMEDIFF(field_name, '$input_date') from tbl_name where condition

at mysql

查看更多
一夜七次
3楼-- · 2019-09-12 00:27

Use TIMEDIFF function instead of substrction:

SELECT REPLACE(TIMEDIFF(col1,col2),'-','')

REPLACE is used to ensure absolute result.

查看更多
We Are One
4楼-- · 2019-09-12 00:35

This question was already answerd... well You need to convert it on timestamps

$time1 = strtotime($row[0]);
$time2 = strtotime($row[1]);
$diff = $time2 - $time1;

Also be aware if it use after 1 day, it will not show the "last day" difference... So use year month day...

查看更多
登录 后发表回答