Sum Time column
-
Thursday, February 07, 2013 12:59 PM
hi
I want to sum time part in datetime column.
ID SK_ID DateTime
1 2 2012-12-12 12:50:59.000
1 2 2012-12-12 12:50:44.000
1 2 2012-12-12 12:49:52.000Sum of
12:50:59.000
12:50:44.000
49:52.000
pls help me on it
/R.
All Replies
-
Thursday, February 07, 2013 1:08 PM
Convert minutes into seconds then back to miuntes
please refer
http://stackoverflow.com/questions/7793531/how-can-i-get-the-sum-of-multiple-datetime-values
please mark as answer if helpful
- Proposed As Answer by Rajeev Harbola Thursday, February 07, 2013 1:09 PM
- Marked As Answer by Iric WenModerator Tuesday, March 05, 2013 1:40 AM
-
Thursday, February 07, 2013 1:09 PMModerator
Try
select sum(datepart(hour,[DateTime]) * 3600 +
datepart(minute,[DateTime]) * 60 + datepart(second, [DateTime])) as [Duration in Seconds]
from myTable
Once you got duration in seconds you can change it back to total hours, total minutes and seconds by applying the same formula in reverse.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Edited by Naomi NMicrosoft Community Contributor, Moderator Thursday, February 07, 2013 1:11 PM
- Proposed As Answer by SQL Novice 01 Thursday, February 07, 2013 3:37 PM
-
Thursday, February 07, 2013 1:10 PM
Its one column value ....
/R.

