Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For-loop and DateTime Problem

Tags:

c#

for-loop

I'm trying to make use for on a DateTime like this:

for (DateTime d = _BookedCheckIn; d <= _BookedCheckOut; d.AddDays(1))
{
    // ...
}

But the problem is that d does not increase. Does anyone have an idea of what the problem is?

like image 954
Irakli Lekishvili Avatar asked Aug 29 '11 23:08

Irakli Lekishvili


1 Answers

You need to use:

for (DateTime d = _BookedCheckIn; d <= _BookedCheckOut; d = d.AddDays(1))
{

When you call d.AddDays, it's returning a new DateTime, not changing the one you already created.

like image 172
Reed Copsey Avatar answered Nov 15 '22 15:11

Reed Copsey