Furqan Sehgal
Furqan Sehgal

Reputation: 4997

Calculating time difference in seconds

I am using following code to calculate time difference. I want to display it in seconds, not in HH:MM:SS Please advise.

Dim myTime = DateTime.Parse("15:40:00 PM")
    Dim vrNowTime = DateTime.Parse(TimeOfDay)
    Dim result = vrNowTime - myTime
    Label1.Text = vrNowTime & "   " & myTime
    MsgBox(result.ToString)

Thanks

Upvotes: 4

Views: 17587

Answers (2)

Mad Dog Tannen
Mad Dog Tannen

Reputation: 7244

You can also use

Dim Result = DateDiff(DateInterval.Second,Time1,Time2)

Upvotes: 5

Teejay
Teejay

Reputation: 7471

Use result.TotalSeconds (and round it if you want an integer number to be displayed).

Also you may want to write simply:

Dim result as TimeSpan = Now() - myTime

Upvotes: 11

Related Questions