我对这段代码有一个问题,它似乎无法解决我做错的事情吗?
DepartureDate = DatePicked
DateTime today = DateTime.Today;
DateTime seven = DateTime.Today.AddDays(+7);
DateTime dt = Convert.ToDateTime(DepartureDate);
if (columnName == "DepartureDate")
{
//range between today and seven days ahead +7
if (dt >= today || dt <= seven)
{
result = valid;
return result;
}
//can't be in the past
if (dt < today)
{
result = "Can't be in the past";
return result;
}
}
答案 0 :(得分:2)
您在范围内的检查是使用OR代替AND。
尝试更改:
if (dt >= today || dt <= seven)
为:
if (dt >= today && dt <= seven)
答案 1 :(得分:0)
更改
if (dt >= today || dt <= seven)
到
if (dt >= today && dt <= seven)