Click here to Skip to main content
11,706,455 members (45,202 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
For example, my input time:
record time unload time
11:37:05 PM 11:39:09 PM
11:44:56 PM 1:7:23 AM

My output should look like:

record time unload time total time
11:37:05 PM 11:39:09 PM 0:2:04
11:44:56 PM 1:7:23 AM 1:22:27

How can I get this in sql?
Posted 27-Dec-12 0:44am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

see the below answer:-
SELECT datediff(Minute,'2006-11-10 05:47:53.497','2006-11-10 08:48:10.420')

also check the below links which will helps you

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74746[^]
http://msdn.microsoft.com/en-us/library/ms189794.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

select
 
    convert(varchar,datediff(hh,convert(datetime,[record time]) ,convert(datetime,[unload time]) ))
    + ':' +
    convert(varchar,datediff(mi,convert(datetime,[record time]) ,convert(datetime,[unload time]) )%60)
    + ':' +
    convert(varchar,datediff(ss,convert(datetime,[record time];) ,convert(datetime,[unload time]) )%60)
    as Duration
    
From YourTable
Happy Coding!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 197
1 Sergey Alexandrovich Kryukov 141
2 chainerlt 110
3 ppolymorphe 71
4 Mika Wendelius 70
0 OriginalGriff 9,070
1 Sergey Alexandrovich Kryukov 8,413
2 CPallini 5,189
3 Maciej Los 4,746
4 Mika Wendelius 3,676


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100