Skip to content

How a datetime is stored in SQL Server

March 30, 2007

Have you ever wondered how dates/times are stored in SQL Server? Probably not, but it’s still interesting to know. There are two date/time formats available in SQL Server: DATETIME and SMALLDATETIME.

DATETIME is stored as two 4-byte integers while SMALLDATETIME is stored as two 2-byte integers. Both integers represent offsets, one is the number of days from that historic day in January 1, 1990, the other is the number of units since midnight. Where the unit for DATETIME is a clocktick and a minute for SMALLDATETIME.

So does anyone else see a problem here? What will happen in January 1, 1990 + 2^15-1 days?

Advertisements

From → sql

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: