if object_id( 'dbo.GetElapsedTime' ) is not null drop function dbo.GetElapsedTime go create function dbo.GetElapsedTime ( @Start DATETIME2(6), @End DATETIME2(6) ) RETURNS NVARCHAR(60) AS BEGIN DECLARE @years INT, @months INT, @days INT, @hours INT, @minutes INT, @seconds INT, @fractionalseconds INT, @temp DATETIME2(6), @return NVARCHAR(30), @StartNS INT = CONVERT( INT, RIGHT( CONVERT( NVARCHAR(60), @Start, 121 ), 6 ) ), @EndNS INT = CONVERT( INT, RIGHT( CONVERT( NVARCHAR(60), @End, 121 ), 6 ) ) SELECT @days = CASE WHEN DATEDIFF( hour, @Start, @End ) > 23 THEN DATEDIFF( day, @Start, @End ) ELSE 0 END; SELECT @temp = DATEADD( day, @days, @Start ) SELECT @hours = CASE WHEN DATEDIFF( minute, @temp, @End ) > 59 THEN DATEDIFF( hour, @temp, @End ) ELSE 0 END; SELECT @temp = DATEADD( hour, @hours, @temp ) SELECT @minutes = CASE WHEN DATEDIFF( second, @temp, @End ) > 59 THEN DATEDIFF( minute, @temp, @End ) ELSE 0 END; SELECT @temp = DATEADD( minute, @minutes, @temp ) SELECT @seconds = DATEDIFF( second, @temp, @End ) + CASE WHEN @StartNS > @EndNS THEN -1 ELSE 0 end ; SELECT @fractionalseconds = CASE WHEN @StartNS > @EndNS THEN 1000000 - @StartNS + @EndNS ELSE @EndNS - @StartNS END SELECT @return = CASE WHEN @days > 0 then CONVERT( NVARCHAR, @days ) + N'd ' ELSE N'' END + RIGHT( N'0' + CONVERT( NVARCHAR, @hours ), 2 ) + N':' + RIGHT( N'0' + CONVERT( NVARCHAR, @minutes ), 2 ) + N':' + RIGHT( N'0' + CONVERT( NVARCHAR, @seconds ), 2 ) + N'.' + RIGHT( N'00000' + CONVERT( NVARCHAR, @fractionalseconds ), 6 ) RETURN @return END go select Elapsed = dbo.GetElapsedTime( '2000-01-01 00:00:00.000000', '2000-12-31 23:59:59.999999' ) /* Elapsed ------------------------------ 365days 23:59:59.999999 */ select Elapsed = dbo.GetElapsedTime( '2001-01-01 00:00:00.000000', '2001-12-31 23:59:59.999999' ) /* Elapsed ------------------------------ 364days 23:59:59.999999 */ select Elapsed = dbo.GetElapsedTime( '2001-12-31 23:59:59.999999', '2002-01-01 00:00:00.000000' ) /* Elapsed ------------------------------ 00:00:00.000001 */ select Elapsed = dbo.GetElapsedTime( '2002-01-01 00:00:00.000000', '2002-02-02 02:02:02.000002' ) /* Elapsed ------------------------------ 00:00:00.000001 */ go
Categories
- Android (2)
- Backpacking (5)
- BBQ (3)
- Bikes (3)
- Boy Scouts (6)
- Breakfast (2)
- Cars (1)
- Chinese (2)
- CMD (8)
- eBooks (1)
- ELL (1)
- Family (13)
- Favorite Poetry (6)
- Flame (1)
- Fun (29)
- Instructables (4)
- Joannie (38)
- LDS Church (12)
- Men's Health Lists (2)
- Oracle (2)
- Pixar (1)
- PowerShell (4)
- Productivity (1)
- Projects (8)
- Recipe (46)
- Reign (2)
- RV (1)
- Scouting (7)
- Security (1)
- Shopping (7)
- Smoking (3)
- Softball (7)
- Sports (6)
- SQL Server (61)
- Stealth (1)
- Tools (58)
- Video (23)
- Visual Studio (5)
- Webelos (2)
Recent Posts
Archives
-
►
2014
(2)
- ► 04/20 - 04/27 (1)
- ► 03/30 - 04/06 (1)
-
►
2013
(9)
- ► 11/24 - 12/01 (3)
- ► 10/06 - 10/13 (1)
- ► 09/08 - 09/15 (1)
- ► 08/18 - 08/25 (2)
- ► 06/09 - 06/16 (1)
- ► 04/28 - 05/05 (1)
-
▼
2012
(12)
- ► 06/24 - 07/01 (1)
- ► 06/03 - 06/10 (3)
- ► 05/27 - 06/03 (1)
- ► 05/20 - 05/27 (2)
- ► 04/22 - 04/29 (1)
- ► 03/18 - 03/25 (3)
-
►
2011
(84)
- ► 12/11 - 12/18 (1)
- ► 10/30 - 11/06 (2)
- ► 10/16 - 10/23 (1)
- ► 10/09 - 10/16 (1)
- ► 09/04 - 09/11 (1)
- ► 08/28 - 09/04 (1)
- ► 07/10 - 07/17 (4)
- ► 07/03 - 07/10 (2)
- ► 06/26 - 07/03 (6)
- ► 06/12 - 06/19 (2)
- ► 05/29 - 06/05 (1)
- ► 04/17 - 04/24 (1)
- ► 04/10 - 04/17 (2)
- ► 04/03 - 04/10 (2)
- ► 03/13 - 03/20 (1)
- ► 03/06 - 03/13 (1)
- ► 02/27 - 03/06 (1)
- ► 02/20 - 02/27 (1)
- ► 02/13 - 02/20 (5)
- ► 02/06 - 02/13 (1)
- ► 01/30 - 02/06 (41)
- ► 01/23 - 01/30 (4)
- ► 01/09 - 01/16 (1)
- ► 01/02 - 01/09 (1)
-
►
2010
(56)
- ► 12/26 - 01/02 (1)
- ► 12/12 - 12/19 (4)
- ► 12/05 - 12/12 (2)
- ► 11/28 - 12/05 (1)
- ► 11/14 - 11/21 (6)
- ► 10/31 - 11/07 (4)
- ► 10/24 - 10/31 (4)
- ► 10/17 - 10/24 (1)
- ► 10/10 - 10/17 (2)
- ► 10/03 - 10/10 (4)
- ► 09/26 - 10/03 (3)
- ► 09/19 - 09/26 (1)
- ► 09/12 - 09/19 (9)
- ► 08/08 - 08/15 (1)
- ► 06/20 - 06/27 (1)
- ► 04/04 - 04/11 (1)
- ► 03/14 - 03/21 (1)
- ► 02/21 - 02/28 (3)
- ► 02/07 - 02/14 (3)
- ► 01/31 - 02/07 (2)
- ► 01/03 - 01/10 (2)
-
►
2009
(58)
- ► 12/20 - 12/27 (1)
- ► 09/20 - 09/27 (7)
- ► 09/06 - 09/13 (1)
- ► 07/26 - 08/02 (1)
- ► 07/12 - 07/19 (1)
- ► 06/14 - 06/21 (1)
- ► 06/07 - 06/14 (4)
- ► 05/31 - 06/07 (2)
- ► 05/24 - 05/31 (4)
- ► 05/17 - 05/24 (5)
- ► 05/10 - 05/17 (9)
- ► 05/03 - 05/10 (12)
- ► 04/26 - 05/03 (10)
Favorite Links
Favorite Tunes
Pronounced
/
'ri?l'ta?m
,
'ril-
/
Show Spelled Pronunciation
[
ree
-
uh
l-
tahym
,
reel
-
]
Show IPA
–noun
Fishing
.
of or pertaining to the period in which a fisherman must leave to go fishing. |
–adjective
Computers
.
of or pertaining to applications in which the computer must respond as rapidly as required by the user or necessitated by the process being controlled. |