Click here to Skip to main content
11,640,445 members (63,123 online)
Click here to Skip to main content

Adding Time in HH:MM Format - Useful SQL Query

, 7 Jun 2011 CPOL 4.8K
Rate this:
Please Sign up or sign in to vote.
Hi,Here is an alternative for your solutionSELECT CAST(DATEADD(MILLISECOND,SUM(DATEDIFF(MILLISECOND,0,CAST(TMP.TotalTime as DATETIME))),0) as TIME)FROM( SELECT CAST(timeduration AS TIME) TotalTime FROM mytable) TMP
Hi,
Here is an alternative for your solution

SELECT CAST(DATEADD(MILLISECOND,
SUM(DATEDIFF(MILLISECOND,0,
CAST(TMP.TotalTime as DATETIME))),0) as TIME)
FROM
(
    SELECT CAST(timeduration AS TIME) TotalTime FROM mytable
) TMP

License

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

Share

About the Author

Shahriar Iqbal Chowdhury/Galib
Chief Technology Officer
Bangladesh Bangladesh
I am a Software Engineer and Microsoft .NET technology enthusiast. Professionally I worked on several business domains and on diverse platforms. I love to learn and share new .net technology and my experience I gather in my engineering career. You can find me from here

Personal Site
Personal Blog
FB MS enthusiasts group
About Me

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 5 I gave this one a 5 as well. The cod... Pin
cbragdon13-Jun-11 13:50
membercbragdon13-Jun-11 13:50 
GeneralTime datatype is specific to SQL SERVER 2008 Pin
Shahriar Iqbal Chowdhury8-Jun-11 0:48
memberShahriar Iqbal Chowdhury8-Jun-11 0:48 
GeneralThis is fine but not working in MS Sql 2005; "Type time is n... Pin
Jobless Creature7-Jun-11 22:21
memberJobless Creature7-Jun-11 22:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150731.1 | Last Updated 7 Jun 2011
Article Copyright 2011 by Shahriar Iqbal Chowdhury/Galib
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid