TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
SQL Function Get Total Time in HH:MM:SS
Ashish Srivastava
Aug 20
2016
Code
808
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
CREATE
FUNCTION
[dbo].TotalTime
(
@StartTime DATETIME,
@EndTime DATETIME
)
RETURNS
Varchar
(10)
AS
begin
DECLARE
@D
VARCHAR
(400)=
'31784'
Declare
@outTime
Varchar
(10);
SELECT
@D = DATEDIFF(
SECOND
,@StartTime,@EndTime)
SELECT
@outTime =
CONVERT
(
VARCHAR
(5), @D/60/60)
+
':'
+
RIGHT
(
'0'
+
CONVERT
(
VARCHAR
(2), @D/60%60), 2)
+
':'
+
RIGHT
(
'0'
+
CONVERT
(
VARCHAR
(2), @D % 60), 2)
RETURN
@outTime
END
GO
SELECT
dbo.TotalTime(
'2016-08-10 10:36:01.000'
,
'2016-08-10 19:25:45.000'
)
SQL Function
Get Total Time in HHMMSS