我有一个包含不同日期的 (IDcolumn, int)、(Differencecolumn, int) 和 (Datecolumn DateTime) 表。
以及一种计算忽略周末的日期之间差异的方法。
public static double GetBusinessDays(DateTime startD, DateTime endD)
{
double calcBusinessDays =
1 + ((endD - startD).TotalDays * 5 -
(startD.DayOfWeek - endD.DayOfWeek) * 2) / 7;
if ((int)endD.DayOfWeek == 6) calcBusinessDays--;
if ((int)startD.DayOfWeek == 0) calcBusinessDays--;
return calcBusinessDays;
}
我想从今天开始获取每个 Datecolumn 上的每个 GetBusinessDays 值。并将其插入到每个对应的差异列中。
例如
ID Date Difference
1 4-22-2013
2 4-23-2013
3 4-24-2013
假设今天的日期是 2013 年 4 月 28 日。差值必须分别包含 6、5、4。
这是我现在所做的,但它不起作用:(
myDatabaseConnection.OpenConnection();
mySqlCommand.CommandType = CommandType.Text;
mySqlCommand.CommandText = "select * from Table1 where Difference IS Null";
SqlDataReader sqlreader = mySqlCommand2.ExecuteReader();
int i;
while (sqlreader.Read())
{
i = sqlreader.GetInt32(0);
double y = GetBusinessDays(sqlreader.GetDateTime(1), DateTime.Now);
string commandtext = "Update Table1 SET Difference = " + y + " Where ID = " + i + " ";
mySqlCommand.CommandText = " " + commandtext + " ";
}
myDatabaseConnection.CloseConnection();