Reputation: 15
I am trying to get number of batches passed deadline, and number of batches near deadline (2 hours before the deadline). Following can get me if I am one day behind deadline. But how to handle hours?
Get number of batches passed deadline, and number of batches near deadline (2 hours before the deadline
CustomerID;CustomerName;BatchDeadline
1;AAA;1
2;BBB;2
3;CCC;2
4;DDD;3
*BatchDeadline: Number of days after BatchDate, if 2 means second day of BatchDate in Batches table.
BatchID;CustomerID;BatchDate
1;1;2014-12-10 8:00
2;2;2014-12-10 8:10
3;2;2014-12-11 10:20
4;1;2014-12-12 11:10
5;3;2014-12-12 11:12
6;3;2014-12-12 11:22
7;3;2014-12-12 11:23
int passedDeadline = 0;
int nearDeadline = 0;
foreach(customer c in customers)
{
foreach(Batch b in batches)
{
if (b.BatchDate < b.BatchDate(c.BatchDeadline * -1)
passedDeadline++;
}
}
Upvotes: 0
Views: 70
Reputation: 700262
Get the current time (don't get it in the loop as the current time changes all the time):
DateTime now = DateTime.Now;
Calculate the points in time that you want to compare with:
DateTime deadline = b.BatchDate.AddDays(c.BatchDate);
DateTime nearDeadline = deadline.AddHours(-2);
Now just compare the time from the table to the points in time:
if (now > deadline) {
// passed the deadline
} else if (now >= nearDeadline) {
// near the deadline
}
Upvotes: 1