排除特定的DateTime

时间:2015-03-05 09:08:28

标签: c# .net

客户表:

CustomerID;CustomerName;BatchDeadline
1;AAA;1
2;BBB;2
3;CCC;2
4;DDD;3

* BatchDeadline:BatchDate之后的天数,如果2表示批处理表中第二天的BatchDate。

批次表:

BatchID;CustomerID;BatchDate
1;1;2015-03-02 8:00
2;2;2015-03-02 8:10
3;2;2015-03-03 10:20
4;1;2015-03-04 11:10
5;3;2015-03-04 11:12
6;3;2015-03-04 19:22
7;3;2015-03-05 11:23

我试图获得超过截止日期的批次数,以及截止日期(截止日期前2小时)的批次数。

DateTime now = DateTime.Now;
foreach(customer c in customers)
{
  foreach(Batch b in batches) 
  {
     DateTime deadline = b.BatchDate.AddDays(c.BatchDate);
     DateTime nearDeadline = deadline.AddHours(-2);

     if (now > deadline) {
        // passed the deadline
     } else if (now >= nearDeadline) {
        // near the deadline
     }
  }
}

上述代码在我24小时办理登机手续时工作正常。如何在上午8点到下午4点之间检查?

说清楚:我想要在晚上时间,包括办公时间。在办公时间上午8点到下午4点检查通过截止日期和截止日期的批次。

0 个答案:

没有答案
相关问题