[RESOLVED] Convert HH:MM into seconds
Hey Folks,
I have 2 values that i have extracted from a website in 2 textboxs.
text1 = 7:6
text2 = 7:06:33
is there any ways in VB6 to convert them into Seconds ?
text3 = 25560
test4 = 25593
?? have been trying to code it since past 2 weeks but no luck with the status as n00b cant do much too :(
Please anyone :wave:
Re: Convert HH:MM into seconds
Convert it to datetime data type using CDATE() or TimeSerial() functions then get number of seconds elapsed using DateDiff() function.
msgbox datediff("s", 0, time) 'sample using built in function time that returns current time
Please take note of the duration you are testing as dates are represented internally as numbers with the whole number portion as the number of days and the decimal portion the part of a day, e.g. half a day is 0.5.
msgbox datediff("s", 0, now) 'seconds since min date supported
msgbox datediff("s", date, now) 'seconds since midnight
Re: Convert HH:MM into seconds
Code:
dim MyDate as Date
dim X as long
MyDate = cdate(text1.text)
X = (datepart("h",MyDate) * 3600) + (datepart("n",MyDate) * 60) + datepart("s",MyDate)
Re: Convert HH:MM into seconds
thanks a lot for your time leinad31 & longwolf
with the correct terms i must walk the correct path.
let me try and get back to ya all
:thumb:
Re: Convert HH:MM into seconds
Another way:
Code:
s = CDate(Text1.Text) * 86400 '-- 24*60*60 = 86400
Re: Convert HH:MM into seconds
Quote:
Originally Posted by anhn
Another way:
Code:
s = CDate(Text1.Text) * 86400 '-- 24*60*60 = 86400
Coool!!! :)
Re: Convert HH:MM into seconds
Final Code
put this on a button with 2 text box. :)
Code:
Dim MyDate As Date
Dim X As Long
MyDate = CDate(Text1.Text)
X = (DatePart("h", MyDate) * 3600) + (DatePart("n", MyDate) * 60) + DatePart("s", MyDate)
Text2.Text = X
Is this the fasted Resolved thread on the forum ;)
Super thanks to all ..you really made my day :)
Simon