【发布时间】:2012-08-12 12:28:10
【问题描述】:
我试图测试员工工作的月份是否等于从他们开始工作到现在的 3 个月。这就是我想要使用的:
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();
我数据库中日期的格式是07/05/2012 但我得到了错误:
startIndex cannot be larger than length of string. Parameter name: startIndex
谁能告诉我,我在这里做错了什么?提前致谢。
【问题讨论】:
-
您的代码适用于名为 result 的变量。但是我们既看不到类型也看不到它的当前值。你能详细说明一下吗?
标签: c#