Reputation: 3911
See i have this following code below, at line no.9 i'm calculating some dates to move forward, so im using AddDays
method but in return i'm getting all dates same for all rows.
If i do AddDays(6)
like this then it is returning correctly by moving all dates by 6 days.
How should i do it for adding days according to my logic at this point.
[DataContract]
public class JQGridRow
{
[DataMember]
public long id;
[DataMember]
public object[] cell;
}
var sortedItems = invBatch.ListOfItems.OrderBy(i => i.RunDateIndex);//This will return IEnumerable<Class> List
DateTime startDate = DateTime.Parse(lblStartDate.Text);
JQGrid.JQGridRow[] rowData = (
from i in sortedItems
select new JQGrid.JQGridRow() {
id = i.ID,
cell = new string[] {
i.ID.ToString(),
i.Status.ToString(),
i.StatusTitle,
i.RunDate.AddDays((startDate.Subtract(i.RunDate)).Days+1).ToString(Utility.DATE_FORMAT),
//Here in above line the array returning same values for all columns of this row
i.StartTimeString,
i.EndTimeString,
i.EndTime.ToString(),
}}).ToArray();
Upvotes: 0
Views: 154
Reputation: 5510
The dates are all same and equal the next day after startDate
because you calculate them as such.
i.RunDate.AddDays((startDate.Subtract(i.RunDate)).Days+1)
Rounding to whole day, you compute RunDate+(startDate-RunDate+1) = startDate + 1. i.RunDate
does not matter.
Upvotes: 3