Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

Probably with the corresponding cast to varbinary:

SELECT CAST(CAST('2012-12-15' AS DATE) AS VARBINARY)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top