fn_elapsed_time (Transact_SQL)

See also: fn_date2ts, fn_timestamp 


 

This scalar UDF returns duration of an event basen on start and end datetime.
 

Syntax

 fn_elapsed_time(@start_date,@end_date)

 

Arguments

@start_date = DATETIME , DEFAULT GETDATE(), date when event started ;

@end_date = DATETIME , DEFAULT GETDATE(), date when event ended ;

Return type

 NVARCHAR(50)

Remarks

If @end_date is before @start_date negative elapsed time is returned

 

Permissions

Public

Dependencies

none

 

Examples

1. SELECT [Lib].[tsql].[fn_elapsedtime](DEFAULT,DEFAULT) => Result: '0d 00:00:00'

equivalent to

SELECT [Lib].[tsql].[fn_elapsed_time](GETDATE(),GETDATE()) => Result: '0d 00:00:00'

2. SELECT [Lib].[tsql].[fn_elapsed_time]('8/28/2012 11:30:00 AM',GETDATE()) => Result: '0d 23:14:29'

Other

none

 


Last edited Aug 29, 2012 at 1:36 PM by adudau, version 1

Comments

No comments yet.