
June 25th, 2012, 11:47 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 1
Time spent in forums: 31 m 5 sec
Reputation Power: 0
|
|
|
(VS 2010) Determine time difference
Hello,
I'm stuck on the part where I need to determine the time difference from my database. Basically data gets recorded onto the database from a different form and gets displayed on this form...
http ://i.imgur.com/tOgwJ.png
What I need to do is,
1. calculate the time worked from the start of the week day till the end of it. So, in this case the time worked should be 1:36:13, not the 12 hours...
2. Is there a way to keep on calculating when the day changes and start off with the same procedure as mentioned above (i.e. start from the 1st entry on Friday and calculate till the last entry of that day).
The code:
PHP Code:
Public Class frmDisplay
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TimelogDataSet.timeLog' table. You can move, or remove it, as needed.
Me.TimeLogTableAdapter.Fill(Me.TimelogDataSet.timeLog)
Me.dtpStart.Value = DateTime.Now.AddDays(-7)
Me.dtpEnd.Value = DateTime.Now.Date
TimeLogBindingSource.Filter = String.Format("currentDate >= #{0:M/dd/yyyy}# AND currentDate <= #{1:M/dd/yyyy}#", dtpStart.Value = DateTime.Now.AddDays(-7), dtpEnd.Value)
End Sub
Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEnd.ValueChanged
End Sub
Private Sub dtpStart_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStart.ValueChanged
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim difference As TimeSpan = dtpEnd.Value - dtpStart.Value
TimeLogBindingSource.Filter = String.Format("currentDate >= #{0:M/dd/yyyy}# AND currentDate <= #{1:M/dd/yyyy}#", dtpStart.Value, dtpEnd.Value)
Me.lblDisplay.Visible = False
Me.lblTimeWorked.Text = DateDiff(DateInterval.Minute, dtpStart.Value, dtpEnd.Value)
If difference.Minutes <> 0 Then
Me.lblTimeWorked.Text = difference.Hours.ToString() & " hours." & " and " & difference.Minutes.ToString() & " minutes."
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'TimeLogBindingSource.Filter = String.Format("currentDate >= #{0:M/dd/yyyy}# AND currentDate <= #{1:M/dd/yyyy}#", dtpStart.Value = DateTime.Now, dtpEnd.Value)
End Sub
End Class
I'd appreciate your help.
|