## 4 replies

Last post Feb 18, 2009 05:46 AM by vijjendra

Member

9 Points

77 Posts

### Time difference between two time in vb .net

Hi friends,

I need to calculate the time difference between two time:

eg: 11:56:00PM and 12:12:00 Am

ouput is 16 minutes.

Can any one give me the code for it.

Thanks,

venkat..

vb.net

All-Star

50169 Points

7539 Posts

Moderator

### Re: Time difference between two time in vb .net

Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
• ### vinz

All-Star

100265 Points

19171 Posts

MVP

### Re: Time difference between two time in vb .net

#### venkatramcse

I need to calculate the time difference between two time:

eg: 11:56:00PM and 12:12:00 Am

ouput is 16 minutes.

Can any one give me the code for it.

Here's an example:

C#

```DateTime dFrom;
DateTime dTo;
string sDateFrom = "11:56:00";
string sDateTo = "12:12:00";
if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo))
{
TimeSpan TS = dTo - dFrom;
int hour = TS.Hours;
int mins = TS.Minutes;
int secs = TS.Seconds;
string timeDiff = hour.ToString("00") + ":" + mins.ToString("00") + ":" + secs.ToString("00");
Response.Write(timeDiff); //output 16 mins in format 00:16:00
}```

VB.NET

```Dim dFrom As DateTime
Dim dTo As DateTime
Dim sDateFrom As String = "11:56:00"
Dim sDateTo As String = "12:12:00"
If DateTime.TryParse(sDateFrom, dFrom) AndAlso DateTime.TryParse(sDateTo, dTo) Then
Dim TS As TimeSpan = dTo - dFrom
Dim hour As Integer = TS.Hours
Dim mins As Integer = TS.Minutes
Dim secs As Integer = TS.Seconds
Dim timeDiff As String = ((hour.ToString("00") & ":") + mins.ToString("00") & ":") + secs.ToString("00")
Response.Write(timeDiff)'output 16 mins in format 00:16:00
End If
```

Vincent Maverick Durano, MVP

Star

8807 Points

3271 Posts

### Re: Time difference between two time in vb .net

Feb 18, 2009 05:38 AM|suthish nair|LINK

Participant

1111 Points

364 Posts