请有人可以提供帮助:(,我首先要结合日期和时间(例如:(DatetaskStart,TimetaskStart),(DatetaskEnd,TimetaskEnd))。
在我的dategridview中,我希望在获得的组合(任务开始的(日期,时间))和(结束任务的(日期,时间))之间进行减法,最后得到所有小时的总时间获得的任务。
Dim sql As String = "select id_task, DatetaskStart ,TimetaskStart , DatetaskEnd ,TimetaskEnd from task where id_task = " & Textbox1.Text & " and Datetask Between '" & DateTimePicker1.Text & "' And '" & DateTimePicker2.Text & "';"
command.CommandText = sql
Dim Time_task as Double
Dim total as Double
Dim DateValue As Date
Dim DateValue2 As Date
connection.Open()
Dim ds As New DataSet
Dim SQLAdapter As New MySqlDataAdapter(sql, connStr)
SQLAdapter.Fill(ds, "connectString")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "connectString"
DataGridView1.AutoResizeColumns()
connection.Close()
For Each row As DataGridViewRow In DataGridView1.Rows
Time_task += (Date.TryParse(row.Cells(3).Value + " " + row.Cells(4).Value, DateValue)) - (Date.TryParse(row.Cells(1).Value + " " + row.Cells(2).Value, DateValue2))
Next
total = Time_task
TextBox7.Text = total
答案 0 :(得分:0)
你需要这样的东西;
Dim TaskEnd As DateTime
Dim TaskStart As DateTime
Dim result As TimeSpan = TaskEnd - TaskStart
MsgBox(result.TotalHours)
VB有一个TimeSpan,当你需要跟踪持续时间时,请使用它!
请下次,尽量不要拖入任何不相关的项目。这个问题与datagridview无关......它与日期和时间有关......