Link to home
Start Free TrialLog in
Avatar of TomBalla
TomBallaFlag for United States of America

asked on

subtract start time from finish time

In visual studio 2012 I have a report set up with a start time and finish time.  What do I need to do to subtract the times and show a total hours?
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim start_time as DateTime= DateTime.Parse(your start time here)
Dim end_time as DateTime = DateTime.Parse(your end time here)
Dim ts as TimeSpan = end_time.Subtract(start_time) 
MessageBox.Show("Total hours elapsed : " &  ts.Hours.ToString())

Open in new window

Avatar of TomBalla

ASKER

Where do I put this code?
can you post your code?
Imports Microsoft.Reporting.WinForms

Public Class downtimebydepartment

    Private Sub downtimebydepartment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MainTableAdapter.Fill(Me.maintenanceDataSet1.Main)

    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Close()
        form1.Show()
    End Sub

    Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
        Me.MainTableAdapter.Fill(Me.maintenanceDataSet1.Main)

        Dim department As New ReportParameter("choosedept", txtChooseDept.Text)
        Me.MainTableAdapter.Fill(Me.maintenanceDataSet1.Main)
        ReportViewer1.LocalReport.SetParameters(New ReportParameter() {department})

        Dim startdate As New ReportParameter("choosestartdate", dtpChooseStartDate.Value)
        Me.MainTableAdapter.Fill(Me.maintenanceDataSet1.Main)
        ReportViewer1.LocalReport.SetParameters(New ReportParameter() {startdate})

        Dim finishdate As New ReportParameter("choosefinishdate", dtpChooseFinishDate.Value)
        Me.MainTableAdapter.Fill(Me.maintenanceDataSet1.Main)
        ReportViewer1.LocalReport.SetParameters(New ReportParameter() {finishdate})
        ReportViewer1.RefreshReport()
    End Sub


End Class

Open in new window

You need to pass another parameter to the report and show it on report. Then you can calculate duration in your VB.NET code and pass value to report just as you are passing start and end times.
You've lost me CodeCruiser.
You are already passing parameters to report. You can pass another parameter for this duration bit. Then just show it on report (like you show other information).
I barely know vb.net so feel free to talk down to me.

What do I add to

Dim t1 as DateTime= DateTime.Parse(your statrt time here)
Dim t2 as DateTime = DateTime.Parse(your endt time here)
Dim ts as TimeSpan = t2.Subtract(t1)

so that the report will see it?  I have a parameter called duration created, but nothing is set in it.