Solved

Sum of a DateTime field to give total number of seconds, or minutes, or both?

Posted on 2008-10-09
7
358 Views
Last Modified: 2010-05-18
I need a simple select query to sum a time field - so 1 minute and 5 seconds plus 30 seconds would result in a total of 1 minute and 35 seconds.

Thanks

Lapchien
0
Comment
Question by:Lapchien
  • 3
  • 3
7 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22677455
What is the datatype of the time field? Format?
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22677506
And what doe your current data look like?
0
 

Author Comment

by:Lapchien
ID: 22677707
datatype is sql datetime
sample of data in field:
1900-01-01 00:00:58.000
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22677935
You can try this:

SELECT SUM(DatePart(ss, timecolumn))
FROM YourTableName

Here is a reference on datepart: http://msdn.microsoft.com/en-us/library/ms174420.aspx
0
 

Author Comment

by:Lapchien
ID: 22677982
SELECT SUM(DatePart(ss, timecolumn)) appears to sum only the seconds part of the time?
0
 

Author Comment

by:Lapchien
ID: 22678079
Think I may have answered my own question, unless you can improve on:

CONVERT(char(8), DATEADD(second, SUM(DATEDIFF(ss, 0, CONVERT(DATETIME, CallDuration, 114))), '0:00:00'), 108)

0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 22678499
I meant to get you the difference in seconds, I apologize. :)

DATEDIFF(dd, 0, CallDuration) ==> gets you call duration date at midnight
DATEDIFF(ss, DATEDIFF(dd, 0, CallDuration), CallDuration) ==> Gets you difference in seconds
SUM(DATEDIFF(ss, DATEDIFF(dd, 0, CallDuration), CallDuration)) ==> gets sum in seconds which can be converted to minutes/seconds by simple math later

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Freeze portion of datamart 2 22
Many to one in one row 2 39
Returning Message/Value Back to Access from a SQL Server trigger 3 34
SQL 2012 Instance Problem 3 55
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question