info@techdevops.com
TechDevOps.com
Explore Tools
Experts in Microsoft SQL Server Operations, Performance, Replication, Cloud & Migrations



T-SQL Getdate as Integer
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)
2017-05-29









T-SQL:

Declare @CurrentDate varchar(100)

Declare @Ext uniqueidentifier = NewID()

Set @CurrentDate = RTRIM(CONVERT(char(10), GetDate(),112)) + '_' + REPLACE(CONVERT(VARCHAR(8), GETDATE(), 108),':', '') +'_'+ CONVERT(varchar(100),(select LEFT(@Ext,8)))

Select @CurrentDate


Example Output:

20170529_203005_6B73B35D

Y 2017
M 05
D 29
T 8:30:05PM


Resources:

NEWID (Transact-SQL)