Pergunta

I have a query like the one described below.

select CAST(0x83360B00 AS Date)

When I run this query in SQL server, I am able to get result in date format as:

2012-12-15

All I want to know is how this is being generated. Thanks in advance.

Foi útil?

Solução

Sql server stores the internal representation of the DATE data type as the big endian count of days from 1 Jan 0001.

So 0x83360B00 is

SELECT 0x83 + 0x36 * 256 + 0x0B * 65536
= 734851 days

Add these back:

DECLARE @Date DATE = '1 Jan 0001'
SELECT DATEADD(dd, 734851, @Date)

Which returns:

2012-12-15

Outras dicas

Probably with the corresponding cast to varbinary:

SELECT CAST(CAST('2012-12-15' AS DATE) AS VARBINARY)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top