从char数据类型到smalldatetime数据类型的转换导致smalldatetime值越界

  数据库字段使用smalldate类型时,如果执行sql语句后出现下面的错误

出错:

消息296,级别16,状态3,第1 行

从char 数据类型到smalldatetime 数据类型的转换导致smalldatetime 值越界。

  应该是传递给smalldatetime字段的时间超过smalldatetime的范围了,smalldatetime 日期范围从1900 年 1 月 1 日到 2079 年 6 月 6 日,自己检查一下时间范围是否正确。或者将smalldatetime修改为datetime类型,扩大时间范围

 

下面的解释来自msdn.
The smalldatetime data type stores dates and times of day with less precision than datetime. The Database Engine stores smalldatetime values as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight.

smalldatetime values that are 29.998 seconds or less are rounded down to the nearest minute; values of 29.999 seconds or more are rounded up to the nearest minute.

Data type Range Accuracy
datetime January 1, 1753, through December 31, 9999 3.33 milliseconds
smalldatetime   January 1, 1900, through June 6, 2079 1 minute

原创文章,转载请注明出处:从char数据类型到smalldatetime数据类型的转换导致smalldatetime值越界

评论(0)Web开发网
阅读(99)喜欢(0)不喜欢(0)SQL及数据库