- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道,为什么 SqlDateTime.MinValue 与 DateTime.MinValue 不一样?
最佳答案
我认为 SQL 和 .NET 的 Date 数据类型之间的差异源于 SQL Server 的 datetime 数据类型、它的最小值和最大值以及它的精度比 .NET 的 DateTime 数据类型古老得多。
随着 .NET 的出现,团队决定 Datetime 数据类型应该有一个更自然的最小值,而 01/01/0001 似乎是一个相当合乎逻辑的选择,而且肯定来自 em>编程语言,而不是数据库角度,这个值更自然。
顺便说一句,在 SQL Server 2008 中,有许多新的基于日期的数据类型( Date 、 Time 、 DateTime2 、 DateTimeOffset )实际上确实提供了更大的范围和精度,并且紧密映射到 .NET 中的 DateTime 数据类型。例如,DateTime2 数据类型的日期范围为 0001-01-01 到 9999-12-31。
SQL Server 的标准“日期时间”数据类型始终具有最小值 01/01/1753(实际上仍然如此!)。我必须承认,我也很好奇这个值的意义,所以也进行了一些挖掘..我发现如下:
During the period between 1 A.D. and today, the Western world has actually used two main calendars: the Julian calendar of Julius Caesar and the Gregorian calendar of Pope Gregory XIII. The two calendars differ with respect to only one rule: the rule for deciding what a leap year is. In the Julian calendar, all years divisible by four are leap years. In the Gregorian calendar, all years divisible by four are leap years, except that years divisible by 100 (but not divisible by 400) are not leap years. Thus, the years 1700, 1800, and 1900 are leap years in the Julian calendar but not in the Gregorian calendar, while the years 1600 and 2000 are leap years in both calendars.
When Pope Gregory XIII introduced his calendar in 1582, he also directed that the days between October 4, 1582, and October 15, 1582, should be skipped—that is, he said that the day after October 4 should be October 15. Many countries delayed changing over, though. England and her colonies didn't switch from Julian to Gregorian reckoning until 1752, so for them, the skipped dates were between September 4 and September 14, 1752. Other countries switched at other times, but 1582 and 1752 are the relevant dates for the DBMSs that we're discussing.
Thus, two problems arise with date arithmetic when one goes back many years. The first is, should leap years before the switch be calculated according to the Julian or the Gregorian rules? The second problem is, when and how should the skipped days be handled?
This is how the Big Eight DBMSs handle these questions:
Pretend there was no switch. This is what the SQL Standard seems to require, although the standard document is unclear: It just says that dates are "constrained by the natural rules for dates using the Gregorian calendar"—whatever "natural rules" are. This is the option that DB2 chose. When there is a pretence that a single calendar's rules have always applied even to times when nobody heard of the calendar, the technical term is that a "proleptic" calendar is in force. So, for example, we could say that DB2 follows a proleptic Gregorian calendar.
Avoid the problem entirely. Microsoft and Sybase set their minimum date values at January 1, 1753, safely past the time that America switched calendars. This is defendable, but from time to time complaints surface that these two DBMSs lack a useful functionality that the other DBMSs have and that the SQL Standard requires.
Pick 1582. This is what Oracle did. An Oracle user would find that the date-arithmetic expression October 15 1582 minus October 4 1582 yields a value of 1 day (because October 5–14 don't exist) and that the date February 29 1300 is valid (because the Julian leap-year rule applies). Why did Oracle go to extra trouble when the SQL Standard doesn't seem to require it? The answer is that users might require it. Historians and astronomers use this hybrid system instead of a proleptic Gregorian calendar. (This is also the default option that Sun picked when implementing the GregorianCalendar class for Java—despite the name, GregorianCalendar is a hybrid calendar.)
以上引用摘自以下链接:
关于.net - SqlDateTime.MinValue != DateTime.MinValue,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/805770/
我在 SQL Server Management Studio 中使用了 SQL 语句,我在其中输入了以下日期时间 {ts '9999-12-31 23:59:59'} 的无限有效性,但是当我尝试通过
考虑以下程序: DateTime dateTime = new DateTime(634546165144647370); SqlDateTime sqlDateTime = new SqlDateT
我使用存储过程来获取分页列表,这是我的方法: using(SqlConnection conn = new SqlConnection(_connectionString)) { using(S
我刚刚发现我的 SqlDateTime.MinValue 在不同的机器上是不同的。 有时是 = DateTime(1953, 1, 1, 0, 0, 0); 但在其他机器上它是 = DateTime(
table = {{ID1, SQLDateTime[{1978, 1, 10, 0, 0, 0.`}]}, {ID2, SQLDateTime[{1999, 1, 10, 0, 0, 0.`}]},
我正在映射一个非常简单的 Users 表,并且我有一个名为“LastLoginDate”的列,它在 sql server 中定义为可为空。 我的映射看起来像这样: public Users {
我似乎无法将 sqldatatime.minvalue 转换为 datetime 对象。 我试过: Datetime dt = Convert.ToDateTime(SqlDateTime.MinVa
我想知道,为什么 SqlDateTime.MinValue 与 DateTime.MinValue 不一样? 最佳答案 我认为 SQL 和 .NET 的 Date 数据类型之间的差异源于 SQL Se
我需要用 SqlDateTime.Parse(val) 其中 val 是一个字符串,例如“23.3.1992 00:00:00 ”。 字符串为欧洲格式,即日在月之前。但是 Parse 需要“美国”格式
我在数据库中使用 NHibernate 持久化我的对象 App 对象定义了一个属性: public virtual DateTime ReleaseDate { get; set; } 在映射类中:
我有一个从源(DataRow 或 SqlDataReader)获取日期属性的方法: protected SqlDateTime GetSqlDateTimePropertyValue(string p
到处找都试过了,还是不行。 目前的方法是 DateTime dt = (DateTime)sqlparam.Value;。我可以想象在不同的配置、不同的 SQL 区域设置、不同的 PC 区域设置等
我不想验证 txtBirthDate,所以我想在数据库中传递 DateTime.MinValue。 我的代码: if (txtBirthDate.Text == string.Empty)
在将 .NET DateTime(默认情况下(DateTime))转换为 SqlDateTime 时,我应该始终检查 .NET 日期是否在 SqlDateTime.MinValue 和 SqlDate
当我将 DateTime 变量与 SqlDateTime.MinValue 进行比较时: if (StartDate > SqlDateTime.MinValue) { // some code
System.DateTime可以采用比 SQL Server 的 DateTime 更广泛的值。因此有类 System.Data.SqlTypes.SqlDateTime模仿后者。 因此,我希望 E
我正在开发一个以 NHibernate 作为后端的 ASP.NET MVC 项目,但在将一些日期写回到我的 SQL Server 数据库表中时遇到一些问题。 这些日期字段不可为空,因此此处有关如何设置
我正在用 c#.net 编写一个与 sql DB 一起工作的应用程序。我有 5 个字段 - 日期时间。当我处于 Debug模式时,我看到 DateTime 字段是正确的,但是当我运行应用程序时,我得到
以下代码使用比较 运算符可以正常编译。 If(dateTimeVariable > SqlDateTime.MinValue) //compiles Ok. dateTimeVariable is o
我正在尝试将日期从 C# 保存到 SQL Server。首先要向用户显示日期格式为 dd/MM/yyyy。然后在 Winforms 屏幕上选择日期后。我想将它保存到数据库中。如果我删除代码中的 dat
我是一名优秀的程序员,十分优秀!