Users: 15,000+ | Page Views: 50,000+ | PPS: 2.5
TechDevOps.com
Explore Tools
{Experts in Microsoft SQL Server Operations, Performance, HA/DR, Data Migrations & Cloud Computing}



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)