Click here to Skip to main content
Click here to Skip to main content
Alternative Tip
Go to top

Adding Time in HH:MM Format - Useful SQL Query

, 7 Jun 2011
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
Technical Lead
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

Comments and Discussions

 
GeneralReason for my vote of 5 I gave this one a 5 as well. The cod... Pinmembercbragdon13-Jun-11 13:50 
GeneralTime datatype is specific to SQL SERVER 2008 PinmemberShahriar Iqbal Chowdhury8-Jun-11 0:48 
GeneralThis is fine but not working in MS Sql 2005; "Type time is n... PinmemberJobless 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 | Mobile
Web03 | 2.8.140926.1 | Last Updated 7 Jun 2011
Article Copyright 2011 by Shahriar Iqbal Chowdhury/Galib
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid