Reputation: 2642
I tried to test the month of the staff working whether equal 3 months from they started work till now. And this is what I am trying to use :
int totalMonth = 3;
int totalYear = 0;
int mon = DateTime.Now.Month;
int yr = DateTime.Now.Year;
//block of code that I used LinQ to Entity to get staff start work date
result = result.Where(((s => mon - int.Parse(s.StartDate.Substring(3, 2).ToString()) == totalMonth && yr -int.Parse(s.StartDate.Substring(6, 4).ToString()) == totalYear))).ToList();
The format of date in my database is 07/05/2012
But I got the error :
startIndex cannot be larger than length of string. Parameter name: startIndex
Could any one tell me , what did I wrong here? Thanks in advanced.
Upvotes: 0
Views: 5301
Reputation: 273169
The format of date in my database is 07/05/2012
Most likely the date is stored as binary and has no format. And what you see when listing the records could be different from what happens in C#.
Use the debugger to find out what result.First().StartDate
actually looks like. Could be "5-7-12"
.
Upvotes: 1