Thinking outside the box

Patron Saint of Lost Yaks
posts - 203, comments - 734, trackbacks - 4

My Links

Advertisement

News

Archives

Post Categories

The internal storage of a SMALLDATETIME value

SELECT  [Now],
        BinaryFormat,
        SUBSTRING(BinaryFormat, 1, 2) AS DayPart,
        SUBSTRING(BinaryFormat, 3, 2) AS TimePart,
        CAST(SUBSTRING(BinaryFormat, 1, 2) AS INT) AS [Days],
        DATEADD(DAY, CAST(SUBSTRING(BinaryFormat, 1, 2) AS INT), 0) AS [Today],
        SUBSTRING(BinaryFormat, 3, 2) AS [Ticks],
        DATEADD(MINUTE, CAST(SUBSTRING(BinaryFormat, 3, 2) AS SMALLINT), 0) AS Peso
FROM    (
            SELECT  CAST(GETDATE() AS SMALLDATETIME) AS [Now],
                    CAST(CAST(GETDATE() AS SMALLDATETIME) AS BINARY(4)) AS BinaryFormat
        ) AS d
 

 

Print | posted on Friday, November 05, 2010 3:14 PM | Filed Under [ SQL Server 2008 Algorithms SQL Server 2005 SQL Server 2000 ]

Feedback

Gravatar

# re: The internal storage of a SMALLDATETIME value

Have you done this for the datetime2 types? It's pretty interesting. :)
12/15/2010 5:35 PM | Rob Volk
Gravatar

# re: The internal storage of a SMALLDATETIME value

Done. Have a look at it here
weblogs.sqlteam.com/...
12/15/2010 10:06 PM | Peso
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET