info@techdevops.com | 437-991-3573 | Data Engineering Services
TechDevOps.com
Resources Tools
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance



T-SQL Getdate as Integer
by BF (Principal Consultant; Architecture; Engineering)
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)