计算两个日期之间的天数 [英] count days between two dates
本文介绍了计算两个日期之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须计算存储过程中两个日期之间的天数。
怎么做?
解决方案
好吧,如果我是使用SQL Server,我会使用DATEDIFF。
对于C#:
DateTime d1 = DateTime.MinValue;
DateTime d2 = DateTime.MaxValue;
TimeSpan span = d2-d1;
对于SQL;
第三列的基本解释如下( d标签以天为单位测量日期差异:
DateDiff( d,[DateReceived],[DateClosed])
如果要添加处理没有关闭日期的记录的异常,使用这个(可选地,如果您只想查看有关闭日期的记录,请添加Is Not Null作为ClosedDate的条件并使用顶部表达式):
IIf(IsNull([DateClosed]), 未关闭消息,DateDiff( d,[DateReceived],[DateClosed]))
OI
http://www.w3schools.com/sql/fu nc_datediff.asp [ ^ ]
I have to count days between two dates in stored procedure.
How to do this?
解决方案
Well, if I was using SQL Server, i would use DATEDIFF.
For C#:
DateTime d1=DateTime.MinValue; DateTime d2=DateTime.MaxValue; TimeSpan span=d2-d1;
For SQL;
The basic interpretation for your third column would be as follows (the "d" tag measures the date difference in days):
DateDiff("d",[DateReceived],[DateClosed])
If you want to add an exception that handles records with no closed date, use this one (optionally, if you just want to look at records where there is a closed date, add "Is Not Null" as the criteria for ClosedDate and use the top expression):
IIf(IsNull([DateClosed]),"Not Closed Message",DateDiff("d",[DateReceived],[DateClosed]))
Good luck,
OI
http://www.w3schools.com/sql/func_datediff.asp[^]
这篇关于计算两个日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文