我有一个DataGridView包含在给定时间段(StartDate,EndDate)中创建的所有点(DateStarttasck,TimeStarttasck)和(DateEndtasck,TimeEndtask),我尝试计算之间的小时数(DateStarttasck,TimeStarttasck) )和(DateEndtasck,TimeEndtask)期间(StartDate,EndDate) 注意:DateStarttasck,TimeStarttasck在DateTimePicker中分别分开 (DateEndtasck,TimeEndtask)(StartDate,EndDate) 所以我首先想要在时间和日期之间进行组合,然后计算小时数
Dim sql As String = "select * from task where id_task = " & Textbox1.Text & " and Datetasck Between '" & DateTimePicker1.Text & "' And '" & DateTimePicker2.Text & "';"
command.CommandText = sql
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()
答案 0 :(得分:0)
使用DateTime.TryParse
尝试将日期字符串和时间字符串转换为单个DateTime
对象,如下所示:
Dim dateValue As Date
If Date.TryParse(dateString + " " + timeString, dateValue) Then
' Successfully parsed date and time strings into the dateValue object
Else
' Unable to parse date and time strings
End If
注意:dateString
是数据库中的日期段,timeString
是数据库中的时间段。
答案 1 :(得分:0)
首先,添加日期和时间(从开始开始)和(结束到结束)
ex:IN C#
DateTime date_Start = DateTime.Parse(StartDate_txt.Text);
DateTime Time_Start = DateTime.Parse(StartTime_txt.Text);
date_Start.AddHours(double.Parse(Time_Start.Hour));
DateTime date_End = DateTime.Parse(EndDate_txt.Text);
DateTime Time_End = DateTime.Parse(EndTime_txt.Text);
date_End.AddHours(double.Parse(Time_End.Hour));
float Diff = date_End.Subtract(date_Start).Hours
我希望你有这个想法对不起,这是在c#中,但希望你能得到这个想法,这在vb中是一样的