I wanted to make a date key from a date column in a table. What is the best manner to convert a date
value into an int
in a ISO format?
CodePudding user response:
I don't use dates expressed as ISO integers but, if I did and even though the formula is a little bit longer that the CONVERT method, it's about 46% faster. On a million rows, that's only a difference of 261 ms compared to 178 (on my box) but I work with billions of rows and every little bit helps.
Here's the formula that I would use if I had to do this type of thing...
YEAR(SomeDateTime)*10000 MONTH(SomeDateTime)*100 DAY(SomeDateTime)
CodePudding user response:
I find this solution, is there better ?
select cast((convert(varchar(10),getdate(),112)) as int)