Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dabram
Starting Member
14 Posts |
Posted - 2010-08-20 : 10:39:31
|
How do I get the minutes for a 24 hour period. I need to get the total minutes from the EndDate - 24 hours.create table TotalTime( ID int identity primary key, StartDate datetime not null, EndDate datetime not null)insert into TotalTime (StartDate, EndDate)select '2010-06-11 03:11:00.000', '2010-06-11 09:10:00.000' union allselect '2009-09-18 06:20:00.000', '2009-09-18 14:17:00.000' union allselect '2010-08-05 21:15:00.000', '2010-08-05 23:30:00.000' union allselect '2010-06-13 18:13:00.000', '2010-06-14 02:03:00.000' union allselect '2010-06-19 19:44:00.000', '2010-06-20 05:10:00.000' union allselect '2010-06-20 06:19:00.000', '2010-06-20 12:20:00.000' union allselect '2010-06-20 18:19:00.000', '2010-06-21 02:34:00.000' union allselect '2010-06-21 04:45:00.000', '2010-06-21 10:05:00.000' union allselect '2010-06-21 12:15:00.000', '2010-06-21 20:23:00.000' select *, DateDiff(MINUTE, StartDate, EndDate) as TotalMinutes from Events--ResultsID StartDate EndDate TotalMinutes1 2010-06-11 03:11:00.000 2010-06-11 09:10:00.000 3592 2009-09-18 06:20:00.000 2009-09-18 14:17:00.000 4773 2010-08-05 21:15:00.000 2010-08-05 23:30:00.000 1354 2010-06-13 18:13:00.000 2010-06-14 02:03:00.000 4705 2010-06-19 19:44:00.000 2010-06-20 05:10:00.000 5666 2010-06-20 06:19:00.000 2010-06-20 12:20:00.000 3617 2010-06-20 18:19:00.000 2010-06-21 02:34:00.000 4958 2010-06-21 04:45:00.000 2010-06-21 10:05:00.000 3209 2010-06-21 12:15:00.000 2010-06-21 20:23:00.000 488Best regards, |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-08-20 : 10:53:21
|
Can you also show us what your expected output should look like. |
|
|
dabram
Starting Member
14 Posts |
Posted - 2010-08-20 : 11:45:58
|
For simplicity, I just changed the dates and times. Last column showing the totals for a 24 hour periodID StartDate EndDate TotalMinutes MinPast24Hours1 2010-06-11 03:00:00.000 2010-06-11 09:00:00.000 360 3602 2010-06-11 10:00:00.000 2010-06-11 12:00:00.000 120 4803 2010-06-11 13:00:00.000 2010-06-11 15:00:00.000 120 6004 2010-06-15 13:00:00.000 2010-06-15 15:00:00.000 120 120 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-08-20 : 12:02:54
|
how do you determine these intervals?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
dabram
Starting Member
14 Posts |
Posted - 2010-08-20 : 16:32:18
|
Thanks for the suggestion, I'll see what I come up with.In answer to your question "how do you determine these intervals?"The interval goes 24 hours back from the EndDate. If the Past24Hours start time is 10 minutes later than the start date, then the total time for the past 24 hours would be 25 minutes. StartDate EndDate Past24Hours Minutes 2010-01-01 15:30 2010-01-01 16:00 2010-01-01 15:35 00:252010-01-02 13:35 2010-01-02 15:35 2010-01-01 15:35 02:00Grand Total would then be 2:25 |
|
|
|
|
|
|
|