Reputation: 25
I have 24 h time stored as last_time
in database and I need to get the difference between current time and last_time
in minutes. I have searched a lot but in all occasions time difference is taken by by two dates. Please tell me how to use DiffDate
function correctly using 24 h formatted time.
Upvotes: 0
Views: 320
Reputation: 1159
For time difference is minutes
SELECT DATEDIFF(mi, last_time, CAST(getdate() as time)) from <TABLE_NAME>
For time difference in DD:MM:SS
declare @null time
SET @null = '00:00:00';
SELECT DATEADD(SECOND, - DATEDIFF(SECOND, last_time, CAST(getdate() as time)), @null) from <TABLE_NAME>
For MYSQL
SELECT TIMEDIFF(last_time, cast( now() as time)) as diff
Upvotes: 2
Reputation: 825
You can use CAST(GETDATE() AS Time)
for the current time.
SELECT DATEDIFF(MINUTE, Last_Time,CAST(GETDATE() AS Time))
FROM TABLE
Upvotes: 1
Reputation: 67
I don't understand too much the question. This query is show difference minutes from last date to current day. Hope it help ?
SELECT DATEDIFF (minute, last_date, current_date)
Upvotes: 1
Reputation: 7197
Try this:
SELECT DATEDIFF(mi, last_time, CONVERT(varchar(10), GETDATE(), 108))
Upvotes: 1