我想比较输入日期与sql server中插入的日期时间 [英] i want to compare a input date with the inserted date time in sql server
本文介绍了我想比较输入日期与sql server中插入的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将输入日期与sql server中插入的日期时间进行比较
DateTime dt = Convert.ToDateTime(01-01-1900);
if((rowLB [CloseDate]是DBNull)!!(Convert.ToDateTime(rowLB [CloseDate] = = dt)))
这是给出错误的唯一增量显示如何比较
i want to compare a input date with the inserted date time in sql server
DateTime dt=Convert.ToDateTime("01-01-1900");
if ((rowLB["CloseDate"] is DBNull) !! (Convert.ToDateTime(rowLB["CloseDate"]==dt)))
this is giving error only increment showing how to compare
推荐答案
你使用感叹号(!!
,ASCII码33)而不是竖条(||
,ASCII代码124):
You're using exclamation marks (!!
, ASCII code 33) instead of vertical bars (||
, ASCII code 124):
DateTime dt = new DateTime(1900, 1, 1);
if (rowLB.IsNull("CloseDate") || Convert.ToDateTime(rowLB["CloseDate"]) == dt)
{
...
}
而不是使用感叹号使用||运算符和使用Datetime比较方法来获取实际结果。
例如,|| dt.CompareTo(Convert.ToDateTime(closedate))== 0)
如果compareTo方法返回基于的值,
小于零 - 此实例早于值。
零 - 此实例与值相同。
大于零 - 此实例晚于值,或者值为空。
Instead of using exclamation mark use || operator and Use the Datetime compare methods to get the actual results.
for example, || dt.CompareTo(Convert.ToDateTime(closedate))==0)
If compareTo method returns the values based on,
Less than zero - This instance is earlier than value.
Zero - This instance is the same as value.
Greater than zero - This instance is later than value, or value is null.
这篇关于我想比较输入日期与sql server中插入的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文