SQL Server - DATE storage question

GreenMachine

In Runtime
Messages
285
Hi! I'm having trouble understanding how the DATE data type storage is 3 bytes in SQL Server.

The DATE data type stores only date values with a range of 0001-01-01 through 9999-12-31 and without hyphens. Therefore the possible range is between 00010101 and 99991231.

That being the case what am I missing here?

1 Byte = 2^8 = 256 (2^8-1= 255)
3 Bytes = 2^24 = 16,777,216 = Largest value stored in 3 bytes
The date 99991231 in binary = 101111101011011111010111111 = 27 BITS

Shouldn't the storage required be 4 Bytes?
 
Could it be between 0001-01-01 and 12-31-9999? I actually don't know how it works, but 12319999 is within three bytes.

12319999 = 101110111111110011111111 = 24 bits, 3 bytes

Just my guess :tongue:
 
You have to be right! I can't believe I didn't look at it that way and it was killing me! Same date range stored and in 3 Bytes.

01-01-0001 = 11110110100101010001 = 20 Bits
12-31-9999 = 101110111111110011111111‬ = 24 Bits

Total Value Range between 01-01-0001 and 12-31-9999
 
Last edited:
Back
Top Bottom