为什么1899-12-30是Access / SQL Server中的零日期而不是12/31?

时间:2022-11-13 19:09:01

More out of curiosity than any real problem; the question came up today and I know I've seen 1899-12-30 used as a "default" date and a zero date in Access and older SQL Server apps. Just wondered why - where did that come from, and why isn't 1899-12-31 used then?

出于好奇心而不是任何真正的问题;这个问题今天出现了,我知道我已经看到1899-12-30用作Access中的“默认”日期和零日期以及较旧的SQL Server应用程序。只是想知道为什么 - 它来自哪里,为什么不使用1899-12-31?

3 个解决方案

#1


41  

Maintaining compatibility with Lotus 1-2-3 back in the day, which had a bug in that it thought the year 1900 was a leap year (or pretended?).

在当天保持与Lotus 1-2-3的兼容性,这有一个错误,它认为1900年是闰年(或假装?)。

The explanation is too long to quote, but for the sake of curiosity, here are some snippets.

解释的时间太长了,但为了好奇,这里有一些片段。

1900 wasn't a leap year.

1900年不是闰年。

"It's a bug in Excel!" I exclaimed.

“这是Excel中的一个错误!”我惊呼道。

"Well, not really," said Ed. "We had to do it that way because we need to be able to import Lotus 123 worksheets."

“嗯,不是真的,”埃德说。 “我们必须这样做,因为我们需要能够导入Lotus 123工作表。”

"So, it's a bug in Lotus 123?"

“那么,它是Lotus 123中的一个错误?”

"Yeah, but probably an intentional one. Lotus had to fit in 640K. That's not a lot of memory. If you ignore 1900, you can figure out if a given year is a leap year just by looking to see if the rightmost two bits are zero. That's really fast and easy. The Lotus guys probably figured it didn't matter to be wrong for those two months way in the past. It looks like the Basic guys wanted to be anal about those two months, so they moved the epoch one day back."

“是的,但可能是故意的。莲花必须适合640K。这不是很多记忆。如果你忽略了1900,你可以通过查看最右边的两位来判断一年是否是闰年这真是快而轻松。莲花家伙可能认为过去这两个月的情况并不重要。看起来那些基本的家伙想要在那两个月做肛门,所以他们感动了有一天回来了。“

Actually, this number is one greater than the actual number of days. This is because Excel behaves as if the date 1900-Feb-29 existed. It did not. The year 1900 was not a leap year (the year 2000 is a leap year). In Excel, the day after 1900-Feb-28 is 1900-Feb-29. In reality, the day after 1900-Feb-28 was 1900-Mar-1 . This is not a "bug". Indeed, it is by design. Excel works this way because it was truly a bug in Lotus 123. When Excel was introduced, 123 has nearly the entire market for spreadsheet software. Microsoft decided to continue Lotus' bug, in order to fully compatible. Users who switched from 123 to Excel would not have to make any changes to their data. As long as all your dates later than 1900-Mar-1, this should be of no concern.

实际上,这个数字比实际天数大一个。这是因为Excel的行为就像1900年2月29日的日期一样。它没。 1900年不是闰年(2000年是闰年)。在Excel中,1900年2月28日之后的那一天是1900年2月29日。实际上,1900年至2月28日的那一天是1900年3月1日。这不是一个“错误”。实际上,它是设计的。 Excel以这种方式工作,因为它确实是Lotus 123中的一个错误。当引入Excel时,123几乎拥有电子表格软件的整个市场。微软决定继续使用Lotus的bug,以便完全兼容。从123切换到Excel的用户不必对其数据进行任何更改。只要你的所有日期都晚于1900年3月1日,这应该是无关紧要的。

#2


0  

To best of my knowledge, date type did not exist in "older SQL Server". It was introduced in SQL Server 2008 having zero date value corresponding to 0001/01/01.

据我所知,“旧SQL Server”中不存在日期类型。它是在SQL Server 2008中引入的,具有对应于0001/01/01的零日期值。

select cast(0x000000 as date),cast(CONVERT(date, '0001/01/01') as varbinary(max)) 
----------     --------
--0001-01-01   0x000000

The statements of questions do not make sense. Were date type existed in " older SQL Server', it would have implied the broken backward compatibility of date type in SQL Server 2008.

问题陈述没有意义。如果日期类型存在于“较旧的SQL Server”中,则会暗示SQL Server 2008中日期类型的向后兼容性损坏。

There is no point in answering (and upvote posts) in the question with undefined or incorrectly defined terms.

使用未定义或错误定义的术语回答(和upvote帖子)没有任何意义。

#3


0  

SQL Server appears to return this date as a default if it cannot contact it's defined time source.

如果SQL Server无法联系其定义的时间源,则SQL Server似乎将此日期作为默认值返回。

I've had this happen during cluster failover incidents when my biometric time attendance system is running / being used.

当我的生物识别考勤系统正在运行/正在使用时,我在群集故障转移事件期间发生了这种情况。

To defeat local clock manipulation, someone clocks in, I ask the SQL cluster instance what time it is.

为了打败本地时钟操作,有人进入,我问SQL集群实例现在是什么时候。

It can't get a valid active time source and returns this date.

它无法获得有效的活动时间源并返回此日期。

Workaround for me is straight forward by checking for this date in my GetServerTime Sub and using local PC time if this 'default' is returned.

通过在我的GetServerTime Sub中检查此日期并使用本地PC时间(如果返回此'default'),我可以直接解决此问题。

I've seen this with SQL 2000/2005/2008, all via ADO and VB6.

我已经通过SQL 2000/2005/2008看到了这一点,所有这些都是通过ADO和VB6实现的。

#1


41  

Maintaining compatibility with Lotus 1-2-3 back in the day, which had a bug in that it thought the year 1900 was a leap year (or pretended?).

在当天保持与Lotus 1-2-3的兼容性,这有一个错误,它认为1900年是闰年(或假装?)。

The explanation is too long to quote, but for the sake of curiosity, here are some snippets.

解释的时间太长了,但为了好奇,这里有一些片段。

1900 wasn't a leap year.

1900年不是闰年。

"It's a bug in Excel!" I exclaimed.

“这是Excel中的一个错误!”我惊呼道。

"Well, not really," said Ed. "We had to do it that way because we need to be able to import Lotus 123 worksheets."

“嗯,不是真的,”埃德说。 “我们必须这样做,因为我们需要能够导入Lotus 123工作表。”

"So, it's a bug in Lotus 123?"

“那么,它是Lotus 123中的一个错误?”

"Yeah, but probably an intentional one. Lotus had to fit in 640K. That's not a lot of memory. If you ignore 1900, you can figure out if a given year is a leap year just by looking to see if the rightmost two bits are zero. That's really fast and easy. The Lotus guys probably figured it didn't matter to be wrong for those two months way in the past. It looks like the Basic guys wanted to be anal about those two months, so they moved the epoch one day back."

“是的,但可能是故意的。莲花必须适合640K。这不是很多记忆。如果你忽略了1900,你可以通过查看最右边的两位来判断一年是否是闰年这真是快而轻松。莲花家伙可能认为过去这两个月的情况并不重要。看起来那些基本的家伙想要在那两个月做肛门,所以他们感动了有一天回来了。“

Actually, this number is one greater than the actual number of days. This is because Excel behaves as if the date 1900-Feb-29 existed. It did not. The year 1900 was not a leap year (the year 2000 is a leap year). In Excel, the day after 1900-Feb-28 is 1900-Feb-29. In reality, the day after 1900-Feb-28 was 1900-Mar-1 . This is not a "bug". Indeed, it is by design. Excel works this way because it was truly a bug in Lotus 123. When Excel was introduced, 123 has nearly the entire market for spreadsheet software. Microsoft decided to continue Lotus' bug, in order to fully compatible. Users who switched from 123 to Excel would not have to make any changes to their data. As long as all your dates later than 1900-Mar-1, this should be of no concern.

实际上,这个数字比实际天数大一个。这是因为Excel的行为就像1900年2月29日的日期一样。它没。 1900年不是闰年(2000年是闰年)。在Excel中,1900年2月28日之后的那一天是1900年2月29日。实际上,1900年至2月28日的那一天是1900年3月1日。这不是一个“错误”。实际上,它是设计的。 Excel以这种方式工作,因为它确实是Lotus 123中的一个错误。当引入Excel时,123几乎拥有电子表格软件的整个市场。微软决定继续使用Lotus的bug,以便完全兼容。从123切换到Excel的用户不必对其数据进行任何更改。只要你的所有日期都晚于1900年3月1日,这应该是无关紧要的。

#2


0  

To best of my knowledge, date type did not exist in "older SQL Server". It was introduced in SQL Server 2008 having zero date value corresponding to 0001/01/01.

据我所知,“旧SQL Server”中不存在日期类型。它是在SQL Server 2008中引入的,具有对应于0001/01/01的零日期值。

select cast(0x000000 as date),cast(CONVERT(date, '0001/01/01') as varbinary(max)) 
----------     --------
--0001-01-01   0x000000

The statements of questions do not make sense. Were date type existed in " older SQL Server', it would have implied the broken backward compatibility of date type in SQL Server 2008.

问题陈述没有意义。如果日期类型存在于“较旧的SQL Server”中,则会暗示SQL Server 2008中日期类型的向后兼容性损坏。

There is no point in answering (and upvote posts) in the question with undefined or incorrectly defined terms.

使用未定义或错误定义的术语回答(和upvote帖子)没有任何意义。

#3


0  

SQL Server appears to return this date as a default if it cannot contact it's defined time source.

如果SQL Server无法联系其定义的时间源,则SQL Server似乎将此日期作为默认值返回。

I've had this happen during cluster failover incidents when my biometric time attendance system is running / being used.

当我的生物识别考勤系统正在运行/正在使用时,我在群集故障转移事件期间发生了这种情况。

To defeat local clock manipulation, someone clocks in, I ask the SQL cluster instance what time it is.

为了打败本地时钟操作,有人进入,我问SQL集群实例现在是什么时候。

It can't get a valid active time source and returns this date.

它无法获得有效的活动时间源并返回此日期。

Workaround for me is straight forward by checking for this date in my GetServerTime Sub and using local PC time if this 'default' is returned.

通过在我的GetServerTime Sub中检查此日期并使用本地PC时间(如果返回此'default'),我可以直接解决此问题。

I've seen this with SQL 2000/2005/2008, all via ADO and VB6.

我已经通过SQL 2000/2005/2008看到了这一点,所有这些都是通过ADO和VB6实现的。