110,534
社区成员
发帖
与我相关
我的任务
分享
string timehour1 = "";
string timehour2 = "";
string timehour3 = "";
string txt = comboBox1.SelectedItem.ToString();
if (txt == "上午")
{
timehour1 = "06:30:00";
timehour2 = "12:00:00";
timehour3 = "08:30:00";
}
string timedate1 = dateTimePicker1.Value.ToString("yyyy-MM-dd ");
string time1 = timedate1 + timehour1;
string time2 = timedate1 + timehour2;
string time3 = timedate1 + timehour3;
string sql= "select id,name, userID, min(time),clockIn from test where time > '" + time1 + "' and time < '" + time2 + "' group by userID";
DbHelper db = new DbHelper();
dataGridView1.DataSource = db.GetDataSet(sql).Tables[0];
int row = dataGridView1.Rows.Count;//得到总行数
for (int i = 0; i < row; i++)//循环表
{
DateTime dateTime = Convert.ToDateTime(dataGridView1.Rows[i].Cells["mintime"].Value);//取得mintime时间
dataGridView1.Rows[i].Cells["clockin"].Value = (dateTime - time3).TotalMinutes.ToString("f0");//计算时间差和赋值
}
还有定义一个全局变量为
private DateTime time3;
将你的代码修改下
string time3 = timedate1 + timehour3;
改成
time3 = Convert.ToDateTime(timedate1 + timehour3);