1) Yes it does. All date arithmetic is handled correctly for you.
2) Yes there is. You can do:
var oneDay = TimeSpan.FromDays(1);
...
begin += oneDay;
You could also use a for
loop:
var oneDay = TimeSpan.FromDays(1);
for (DateTime currentDay = begin; currentDay < end; currentDay += oneDay)
{
// Some code here.
}
One final thing: If you want to be sure to ignore the time component, you can ensure that the time part of the begin and end dates is set to midnight as follows:
begin = begin.Date;
end = end.Date;
Make sure you have your bounds correct. The loop goes while currentDay < end
- but you might need currentDay <= end
if your time range is inclusive rather than exclusive.