# I Want To Know How To Calculate 2 Time Difference

• ### Question

• Plz help for this,

dim date1 as date

dim date2 as date

dim t1,t2

t1=timevalue(date1)

t2=timevalue(date2)

then how to check difference between t1,t2 is greater than 5 minutes

Thankfully, Prashanthi

Wednesday, April 24, 2013 8:45 AM

• Dear Prashanthi,

This should do the trick:

``` Private Function isTimeSpanGreaterThen5Min(startdate As Date, enddate As Date) As Boolean
Dim deltaTimespan As TimeSpan = enddate.Subtract(startdate)
If deltaTimespan.Minutes > 5 Then
Return True
Else
Return False
End If
End Function```

With best regards,

Alex van der Lans
Software Architect | Scrum master
URL: http://www.alexvanderlans.com

MI Consultancy
The Netherlands
URL: http://www.miconsultancy.com

• Proposed as answer by Wednesday, April 24, 2013 9:45 AM
• Marked as answer by Thursday, May 2, 2013 6:24 AM
Wednesday, April 24, 2013 8:49 AM

If Math.Abs(date1.Subtract(date2).TotalMinutes) > 5 Then
'greater than 5 minute difference
Stop
End If

"Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it." JohnWein

• Marked as answer by Thursday, May 2, 2013 6:24 AM
Wednesday, April 24, 2013 1:09 PM

### All replies

• Dear Prashanthi,

This should do the trick:

``` Private Function isTimeSpanGreaterThen5Min(startdate As Date, enddate As Date) As Boolean
Dim deltaTimespan As TimeSpan = enddate.Subtract(startdate)
If deltaTimespan.Minutes > 5 Then
Return True
Else
Return False
End If
End Function```

With best regards,

Alex van der Lans
Software Architect | Scrum master
URL: http://www.alexvanderlans.com

MI Consultancy
The Netherlands
URL: http://www.miconsultancy.com

• Proposed as answer by Wednesday, April 24, 2013 9:45 AM
• Marked as answer by Thursday, May 2, 2013 6:24 AM
Wednesday, April 24, 2013 8:49 AM