Click here to Skip to main content
12,348,850 members (60,272 online)
Rate this:
 
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2016
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