Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert time to seconds 1

Status
Not open for further replies.

dazzer123

IS-IT--Management
Nov 24, 2003
128
0
0
GB
Hi,

I'm having a real problem with something a though would be fairly simple!

I have a time in the format "hh:mm:ss" and I want to convert this into seconds but I just can't work out how to do it.

For example I may have 01:02:04 and I need to convert this into seconds (I thinks its 3724 for the example above)

Any ideas would be greatly appriciated
 
You could use a TimeSpan to return the number of seconds to you...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I just came up with this, however how would TimeSpan work I've tried it but I couldn't seem to get it to do what I wanted. Thanks for your help



Private Function ReturnSeconds(ByVal strTime As String) As Integer
Dim strHours As String
Dim strMinutes As String
Dim strSeconds As String

Dim arrTime() As String

arrTime = strTime.Split(":")

strHours = arrTime(0)
strMinutes = arrTime(1)
strSeconds = arrTime(2)

ReturnSeconds = strHours * 60 * 60
ReturnSeconds += strMinutes * 60
ReturnSeconds += strSeconds


End Function
 
Well as a really quick example (not the best but it at least illustrates how a TimeSpan could be used) you could use something like:
Code:
        Dim ts As TimeSpan = CDate(CDate(DateTime.Today & " 01:02:04")).Subtract(CDate(DateTime.Today))
        Dim intSeconds As Integer = ((ts.Hours * 60) + ts.Minutes) * 60 + ts.Seconds


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top