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

rmbxnbpk  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(393)
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

我想找出时间1和当前时间(以分钟为单位)之间的差异。我不断得到一个错误,所以我假设这可能是一个转换问题,但我不能找出它。
小提琴:http://sqlfiddle.com/#!9/486850/47
有人能给我建议吗?谢谢

yacmzcpb

yacmzcpb1#

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

FROM Test

我猜你的化名让你很难受

3npbholx

3npbholx2#

您可以尝试此查询:

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

此处演示

相关问题