returning a date as an int in t-sql
DECLARE @date AS DATE = GETDATE()
SELECT Date_As_Int = (YEAR(@date) * 10000) +
(MONTH(@date) * 100) +
(DAY(@date))
20240221
This is for those times where you need a datekey, or just want your date as an int. Itβs an alternative to FORMAT plus CAST.
My blog does not host comments. If you want to discuss a post, or say hello, you can hit me up on BlueSky where I'm @ThomasChatting.dev or you can email me at hello (at) thomaschatting (dot) dev.