I want to use AddDays() method in for loop. But it doesn't work. in spite of using in loop, day value is not increasing. Then it is transforming infinite loop. For example;
DateTime exDt = tempPermissionWarning[i].planned_start_date;
for (DateTime dt = exDt; dt <= newTo; dt.AddDays(1))
{
context = context + dt.ToShortDateString() + "æ" + tempPermissionWarning[i].resource_name) + ¨";
}
How I use AddDays() method in a for loop
Thank you so much
dt.AddDays(1)
returns a new object, which you are discarding.
You could use dt = dt.AddDays(1)
in the for
loop, in place of what you currently have.
The AddDays
methods returns a new DateTime
, so your dt
object never gets modified. You can reassign it however. This should work:
for (DateTime dt = exDt; dt <= newTo; dt = dt.AddDays(1)) { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With