none
DATETIME2 Internal Storage Structure

    Question

  • I propose the following:

    DATETIME2 8 bytes (precision > 4) internal storage structure

    o 1st byte: precision like 7

    o middle 4 bytes: number of time units (smallest 100ns) since midnight

    o last 3 bytes: number of days after the base date 0001-01-01

    Is it correct? Thanks.

    DECLARE @dt2 DATETIME2 = '00020101 00:00:00.0000009'
    SELECT convert(binary(9), @dt2);
    -- 0x0709000000006D0100
    
    DECLARE @dt26 DATETIME2(6) = '00020101 00:00:00.000008'
    SELECT convert(binary(9), @dt26);
    -- 0x0608000000006D0100


    Kalman Toth Database & OLAP Architect SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012



    Wednesday, February 12, 2014 6:21 PM
    Moderator