April 26, 2014 at 11:52 am
Hi,
I've table and data as follow,
declare @tAccount table
(
isLocked bit,
LastLockoutDate datetime,
currentDte dateTime
)
insert into @tAccount values('true','2014-04-26 16:11:25.337',getdate())
Let's say, current data as follow,
isLocked| LastLockoutDate| currentDte
12014-04-26 16:11:25.3372014-04-27 01:45:15.053
How to get different in minutes between currentDate and LastLockoutDate? Mean, currentDate - LastLockoutDate.
Really need help
April 26, 2014 at 11:57 am
The DATEDIFF function is your friend here
😎
SELECT
isLocked
,LastLockoutDate
,currentDte
,DATEDIFF(MINUTE,LastLockoutDate,currentDte) AS DIFF_MINUTE
FROM @tAccount
Result
isLocked LastLockoutDate currentDte DIFF_MINUTE
-------- ----------------------- ----------------------- -----------
1 2014-04-26 16:11:25.337 2014-04-26 18:57:15.777 166
April 26, 2014 at 12:00 pm
tq 😀
April 26, 2014 at 12:07 pm
Note that it won't return complete minutes (or any other period) and will count for the times the period changes.
In the following example both calculations return 1 and that is expected.
SELECT DATEDIFF(MI, '20140426 01:00:59.997', '20140426 01:01:00.000'),
DATEDIFF(MI, '20140426 01:00:00.000', '20140426 01:01:59.997')
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply