15,921,577 members
See more:
How to insert date with timespan in for loop one after the other in c#...For instance if its current date and the timespan is 5 days first data must enter 5 days greater then second data 10 days later and so on...
Posted
[no name] 18-Mar-13 9:15am
What have you tried? Did you try AddDays(5)?

## Solution 1

Hi,

What i understand from your query is, if you have 3 records and you would like to insert then you will enter 18+5 (ie todays date and 5), 18+10, 18+15.

To do so you need to use for loop like,

C#
```for(int  i = 5,j=0; j< 3; j++, i = i+5)
{
}

//Note : above code is just to give you idea about logic, syntax may be differ a little bit.```

Thanks
-Amit

## Solution 3

Hi,
Suppose you could do it like this too.

C#
```public void Date()
{
int dateSpan= 5;
int numberOfIteration = 3;
for (int i = 1; i <= numberOfIteration; ++i)
{
DateTime date = DateTime.Now.AddDays(i * dateSpan);
}
}```

dateSpan is the number of days you want to increment by.
numberOfIteration is the number of times you wanted increment the date.

So the date will have added days of dateSpan multiplied by count.

so the first date will be current day + (1 x 5);
so the second ate will be current day + (2 x 5);

and so on....

I hope this helps.

Regards
Jegan

## Solution 2

Use comparison like given below to add values in ascending or descending order

DateTime dt = DateTime.Now;
DateTime dt2 = new DateTime(2013,03,18,18,49,00);
if (dt > dt2)
{
}

v2