VB.net MYSQL - 在数据库中计算2秒之间的秒数

时间:2014-08-27 14:13:14

标签: mysql sql vb.net visual-studio-2012

嗨,我对vb.net有一点问题,不确定要朝哪个方向前进。

程序的前端用于计算某个进程停机时间的秒数。

数据库有下表和示例数据:

  • 状态| startdate |止损|秒


  • 正在运行27/08/2012 11:10:11 27/08/2012 11:10:22 11

  • Running 27/08/2012 11:10:11 27/08/2012 11:10:22 11
  • Running 27/08/2012 12:14:27 27/08/2012 12:14:57 30

在后端,所有即时尝试都是使用日期选择器为日期填充一个带有秒数的标签,在进行查询时我使用datepicker文本并将时间添加到结尾,到没有惊喜它没有工作,也只考虑开始日期,但不是因为我试图在该时间框架内加起来的止损,我希望有人可以提供帮助,这是我在下面尝试的代码:

Dim DTimePicker1 = DateTimePicker1.text & " 11:00:00"
        Dim DTimePicker2 = DateTimePicker1.text & " 12:00:00"

        cmd.Parameters.Clear()
        cmd.CommandText = "SELECT SUM(seconds) FROM sqlccmlinestatus WHERE status = 'Running' and startdate BETWEEN @BEG AND @END"
        cmd.Parameters.AddWithValue("@BEG", DTimePicker1)
        cmd.Parameters.AddWithValue("@END", DTimePicker1)
        Label70.Text = cmd.ExecuteScalar()

任何帮助都会很棒。

非常感谢, 皮特

1 个答案:

答案 0 :(得分:0)

Dim D1 as Date = DateTimePicker1.Value
Dim D2 as Date = DateTimePicker2.Value
Dim DTimePicker1 as new Date(D1.Year, D1.Month, D1.Day, 11, 0, 0)
Dim DTimePicker2 as new Date(D2.Year, D2.Month, D2.Day, 12, 0, 0)
cmd.Parameters.Clear()
cmd.CommandText = "SELECT SUM(seconds) FROM sqlccmlinestatus WHERE status = 'Running' and startdate BETWEEN @BEG AND @END"
cmd.Parameters.AddWithValue("@BEG", DTimePicker1.ToString("yyyy-MM-dd HH:mm:ss.fff"))
cmd.Parameters.AddWithValue("@END", DTimePicker2.ToString("yyyy-MM-dd HH:mm:ss.fff"))
Label70.Text = cmd.ExecuteScalar()