两个日期之间的差异
为了学习,我一直在写一些关于 SQL Server 的查询。
我想知道如何在 SQL 查询中获得今天与 90 天前的差异?
I have been writing some queries about SQL Server in order to learn.
I wonder that how can I get the difference of today between 90 days ago in a SQL query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://msdn.microsoft.com/en-us/library/ms189794.aspx
http://msdn.microsoft.com/en-us/library/ms189794.aspx
您需要 DATEADD,而不是 DATEDIFF,并且您需要决定是否需要90 天前:
或 3 个月前:
You want DATEADD, not DATEDIFF, and you need to decide whether you need 90 days ago:
or 3 months ago:
尝试返回 90 年前的日期和时间:
输出:
这只会为您提供 90 天前的日期,时间为 00:00:00.000:
输出:
try this to return the date and time for exactly 90 ago:
output:
this will give you the date only for 90 days ago, with a time of 00:00:00.000:
output:
这将正确舍入到 3 个月前(而不是 90 天前)的午夜,这似乎是您想要的(08-18 -> 05-18 是 92 天,因为那里有两个 31 日)。
This will round correctly to midnight on the day 3 months ago (not 90 days ago) which seems to be what you want (08-18 -> 05-18 is 92 days since there were two 31sts in there).