fn_timestamp (Transact_SQL)

See also: fn_date2ts, fn_elapsed_time

 


 

This scalar UDF returns timestamp based on date and precission.
 

Syntax

 fn_timestamp(@date,@precission) 

 

Arguments

@date = DATETIME , DEFAULT GETDATE(), date to convert to timestamp format ;

@precission = NVARCHAR(50), indicates the length and format of the timestamp result. Allowed values are:

'Y','YY','YYYY','YEAR'

 'M','MM','MMM','MONTH'

 'D','DD','DDD','DAY'

 'H','HH','HOUR'

'MI','NN','MINUTE'

'S','SS','SECOND'

 'MS','MILISECOND'

 

 

Return type

 

BIGINT

Remarks

none

 

Permissions

Public

Dependencies

none

 

Examples

1. SELECT [Lib].[tsql].[fn_timestamp] (DEFAULT,DEFAULT) => Result:  20120829092035123

equivalent to

SELECT [Lib].[tsql].[fn_timestamp] (GETDATE(),'MILISECOND') => Result: 20120829092035123

2. SELECT [Lib].[tsql].[fn_timestamp] ('7/11/2008 11:54:33.786 AM','HOUR') => Result: 2008071111

Other

Synonym fn_date2ts was created to help code clarity.

 

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

Comments

No comments yet.