Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have one table like this


starting time ending time
16:26:46:235 16:26:50:924

i want time difference..

please help me out
Posted
Comments
Herman<T>.Instance 1-Sep-15 7:56am    
Timediff in seconds?
See DateDiff here
CHill60 1-Sep-15 8:00am    
As per your earlier comment to me - that's the answer!
Herman<T>.Instance 1-Sep-15 8:28am    
done
Maciej Los 1-Sep-15 8:06am    
What have you tried? Where are you stuck?

Hi,

Check this...Sql time difference between two dates result in hhmmss[^]

...with little modifications

SQL
declare @StartDate time, @EndDate time

select @StartDate = '16:26:46:235&',@EndDate='16:26:50:924';

SELECT CONVERT(VARCHAR(12), DATEADD(MS, DATEDIFF(MS, @StartDate, @EndDate), 0), 114) AS TimeDiff



Hope this will help you.

Cheers
 
Share this answer
 
Timediff in seconds?
See DateDiff here
 
Share this answer
 
v3
Try the below code:

SQL
SELECT  CAST(DATEDIFF(HOUR, '16:26:46:235', '16:26:50:924') AS VARCHAR)
         + ':' + CAST(DATEDIFF(MINUTE, '16:26:46:235', '16:26:50:924') AS VARCHAR)
         + ':' + CAST(DATEDIFF(SECOND, '16:26:46:235', '16:26:50:924') AS VARCHAR)
         + ':' + CAST(DATEDIFF(MILLISECOND, '16:26:46:235', '16:26:50:924') AS VARCHAR)


This should give you what you are looking for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900