2个日期之间的时间(分钟)差MySQL

时间:2018-07-18 12:40:28

标签: mysql sql time

CREATE TABLE Test (

id int primary key,
Present varchar(10),
Date date,
Time time
);

INSERT INTO Test (id, Present, Date, Time)
Values (1, 'Present', '2018-07-18', '10:13:55' ),
(2, 'Present', '2018-07-18', '10:10:55' );

查询:

SELECT 
id,
Present,
Date,
Time,
current_time AS 'Current Time',
TIMESTAMPDIFF(MINUTE, [Time], CURRENT_TIME()) AS 'Current Time'

FROM Test

我正在寻找time1和当前时间(以分钟为单位)之间的时差。我不断收到错误消息,所以我假设可能是转换问题,但我无法解决。

提琴:http://sqlfiddle.com/#!9/486850/47

有人可以告诉我谢谢

2 个答案:

答案 0 :(得分:2)

SELECT 
id,
Present,
Date,
Time,
TIMESTAMPDIFF(MINUTE, time, CURRENT_TIMESTAMP())

FROM Test

正在工作,我想您的别名给您带来了麻烦

答案 1 :(得分:0)

您可以尝试以下查询:

SELECT 
id,
Present,
Date,
Time,
current_time as Current,
TIMESTAMPDIFF(MINUTE, Time, CURRENT_TIME()) AS Time_difference
FROM Test;

Demo here