Click here to Skip to main content
13,410,009 members (36,561 online)
Click here to Skip to main content
Add your own
alternative version


Posted 7 Jun 2011

Adding Time in HH:MM Format - Useful SQL Query

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
Here is an alternative for your solution

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


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


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 14:50
membercbragdon13-Jun-11 14:50 
GeneralTime datatype is specific to SQL SERVER 2008 Pin
Shahriar Iqbal Chowdhury8-Jun-11 1:48
memberShahriar Iqbal Chowdhury8-Jun-11 1:48 
GeneralThis is fine but not working in MS Sql 2005; "Type time is n... Pin
Jobless Creature7-Jun-11 23:21
memberJobless Creature7-Jun-11 23:21 

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

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

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