SQL Server:了解DATEDIFF函数 [英] SQL Server: Understanding DATEDIFF function

查看:81
本文介绍了SQL Server:了解DATEDIFF函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解DATEDIFF函数。查询

I have difficulties understanding the function DATEDIFF. When querying

SELECT DATEDIFF(YEAR, 0, getdate())

我得到当年与1900年之间的差,得出111。我认为开始时间应该是时间,而不是像0这样的整数。如何使用0?为什么格式为datetime的年份应该是1900年而不是1753年?

I get difference between current year and year 1900 resulting 111. I think that the starttime should be time, not integer like 0. How 0 can be used? Why the start year in 1900, not 1753 as it should be when format is datetime?

推荐答案

由于隐式,它可以在datetime中起作用将0转换为1900年1月1日。

It works in datetime because of implicit conversion of 0 to 1st January 1900.

为什么不是1900?为什么0 = 1899年12月31日用于MS Access?为什么从1970年1月1日开始使用unix时间戳?

Why not 1900? Why does 0 = 31 Dec 1899 for MS Access? Why are unix timestamps from 01 Jan 1970?

1753也是相当随意的:这是对公历的主要转换,但并不一致。 SQL Server 2008的更新类型也可以追溯到0001年1月1日。

1753 is fairly arbitrary too: it's the major switch to the Gregorian calendar but it isn't consistent. SQL Server 2008 goes back to 01 Jan 0001 with the newer types too.

这篇关于SQL Server:了解DATEDIFF函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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