sql server中datetime的内部表示是什么? [英] What is the internal representation of datetime in sql server?

查看:141
本文介绍了sql server中datetime的内部表示是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储在SQL Server中的日期时间值的基础数据结构是什么(2000和2005如果不同)?那么直到字节表示?

What is the underlying datastructure of datetime values stored in SQL Server (2000 and 2005 if different)? Ie down to the byte representation?

大概在选择datetime列时,默认的表示形式是文化特定的值/可以改变的。也就是说,我们没有看到的一些基础结构被格式化为YYYY-MM-DD HH:MM:SS.mmm。

Presumably the default representation you get when you select a datetime column is a culture specific value / subject to change. That is, some underlying structure that we don't see is getting formatted to YYYY-MM-DD HH:MM:SS.mmm.

原因是,有在我的部门一般持有的视图,它以内存的形式存储在YYYY-MM-DD HH:MM:SS.mmm中,但我确定不是这样。

Reason I ask is that there's a generally held view in my department that it's stored in memory literally as YYYY-MM-DD HH:MM:SS.mmm but I'm sure this isn't the case.

推荐答案

它是存储为8字节字段,其范围从1753-01-01到9999-12-31,准确到0.00333秒。

It's stored as an 8 byte field, capable of a range from 1753-01-01 through 9999-12-31, accurate to 0.00333 seconds.

细节据说是不透明的,但大部分资源(1)(2),我在网路上发现如下:

The details are supposedly opaque, but most resources (1), (2) that I've found on the web state the following:


前4个字节存储自SQL Server时代以来的天数( 1900年1月1日),第二个4个字节存储午夜后的滴答数,tick为3.3毫秒。

The first 4 bytes store the number of days since SQL Server's epoch (1st Jan 1900) and that the second 4 bytes stores the number of ticks after midnight, where a "tick" is 3.3 milliseconds.

前四个字节被签名(可以是正或负),这就解释了为什么可以表示早于纪元的日期。

The first four bytes are signed (can be positive or negative), which explains why dates earlier than the epoch can be represented.

这篇关于sql server中datetime的内部表示是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆