Ryan Gadsdon
Ryan Gadsdon

Reputation: 2378

Time (minutes) difference between 2 dates MySQL

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' );

Query:

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

FROM Test

I am looking to find the difference between time1 and the current time in minutes. I keep getting an error so i am assuming maybe its a conversion issue but i cant figure it out.

fiddle: http://sqlfiddle.com/#!9/486850/47

Can anyone advise me thanks

Upvotes: 0

Views: 51

Answers (2)

Sinto
Sinto

Reputation: 3997

You can try this query:

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

Demo here

Upvotes: 0

Matheus Souza
Matheus Souza

Reputation: 114

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

FROM Test

Is working, I guess your aliases are giving you a hard time

Upvotes: 2

Related Questions