SQL SERVER:获取两个日期之间的总天数
我试图获取两天之间的总天数:
1/1/2011
3/1/2011
RETURN
62
Is it possible to do in SQL Server?
I'm trying to get the total number of days between two days:
1/1/2011
3/1/2011
RETURN
62
Is it possible to do in SQL Server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
PRINT DATEDIFF(DAY, '1/1/2011', '3/1/2011')
会给你你想要的。这给出了两个日期之间跨越午夜边界的次数。如果您将两个日期都包含在计数中,您可能会决定需要加一;如果您不想包含任一日期,则可能需要减一。
PRINT DATEDIFF(DAY, '1/1/2011', '3/1/2011')
will give you what you're after.This gives the number of times the midnight boundary is crossed between the two dates. You may decide to need to add one to this if you're including both dates in the count - or subtract one if you don't want to include either date.
SQL Server DateDiff
SQL Server DateDiff
您可以尝试这个 MSDN 链接
You can try this MSDN link
请参阅 DateDiff:
See DateDiff:
另一种日期格式
Another date format
这对我有用 -
This is working for me -
如果您想做同样的事情存储过程那么您需要应用下面的代码。
其中@fromdate和@todate是SP的参数
if you want to do same thing Store Procedure then you need to apply below code.
where @fromdate and @todate is Parameter of the SP