You must Sign In to post a response.

how to find out the time difference in vb.net

The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
This thread will be reviewed shortly.
If you think this thread contain inappropriate content, please report to webmaster.
how to find out the time difference in vb.net

please tell me the solution as earlier as possible

thank u!

with regards
Satheesh


Comments

Author: ravinderreddy03 Mar 2006 Member Level: Silver   Points : 2

Hi,
take two strings for intime(in) and outtime(out). and write code for diff

DateDiff(DateInterval.Minute, in, out)

U will get diff between time.
All the best......

Author: Bhavesh Rana22 Sep 2006 Member Level: Silver   Points : 2

TimeSpan T1=new TimeSpan(System.DateTime.Now.Day,System.DateTime.Now.Hour,System.DateTime.Now.Minute,System.DateTime.Now.Second,System.DateTime.Now.Millisecond);
MessageBox.Show(T1.ToString());
//Do Your Process...

TimeSpan T2=new TimeSpan(System.DateTime.Now.Day,System.DateTime.Now.Hour,System.DateTime.Now.Minute,System.DateTime.Now.Second,System.DateTime.Now.Millisecond);
MessageBox.Show(T2.ToString());
MessageBox.Show(T2.Subtract(T1).ToString());


I hope this will help !!!!

Vahi,
Bhavesh Rana

Author: Batzoid21 Jan 2007 Member Level: Bronze   Points : 2

This function will calculate the difference between two times.

Public Function TimeDiff(t1, t2)

'Purpose: Calculate the difference between two given times
' t1 and t2. Returns t1 - t2.

Dim sec1, sec2, secOut, minsOut, hoursOut

'Convert times to seconds
sec1 = (Hour(t1) * 3600) + (Minute(t1) * 60) + Second(t1)
sec2 = (Hour(t2) * 3600) + (Minute(t2) * 60) + Second(t2)

'Subtract one from the other
secOut = sec1 - sec2 ' or Add together to sum two times

'Calc hours
hoursOut = Int(secOut / 3600)
secOut = secOut - (hoursOut * 3600)

'Calc minutes
minsOut = Int(secOut / 60)
secOut = secOut - (minsOut * 60)

'Convert back to HH:MM:SS
TimeDiff = TimeValue(Format(hoursOut, "00") + ":" + Format(minsOut, "00") + ":" + Format(secOut, "00"))

End Function

Author: eugene20 Sep 2007 Member Level: Bronze   Points : 2

dim ts as TimeSpan = DateTime.Now.Subtract(TimeStamp)

MesageBox.Show(ts.TotalSeconds.toString());

Author: Panamayan Purushothaman30 May 2008 Member Level: Gold   Points : 2

DateDiff(DateInterval.Minute, intime, outtime)

Author: shinurag06 Nov 2008 Member Level: Silver   Points : 4

Dim dt1 As TimeSpan
Dim dt2 As TimeSpan
Dim dt3 As TimeSpan


dt1 = DateTimePicker1.Value.TimeOfDay
dt2 = DateTimePicker2.Value.TimeOfDay
dt3 = dt2.Subtract(dt1)

If dt3.Hours < 1 And dt3.Minutes < 1 And dt3.Seconds < 1 Then
MsgBox("Date interval mismatch")
End If

set datetimepicker's format as time
set datetimepicker's ShowUpDown as true

Shinurag.