|
-
Dec 6th, 2003, 06:50 PM
#1
Thread Starter
Lively Member
Arithmetic with times
Hi i have two times in the format mm.ss (minutes.seconds)
I want to subtract 1 minute and thirty seconds from 30 minutes eg. x = 30.00 - 1.30
If i did that normally the result would be 28.7
I of course want the answer to be 28.30
Are there any mathematical genii out there who can help me?
Thanks in advance, John
-
Dec 6th, 2003, 11:12 PM
#2
VB Code:
Private Function TimeDiff(ByVal strTime1 As String, ByVal strTime2 As String) As String
Dim sMinutes As Short = Split(strTime1, ".")(0) - Split(strTime2, ".")(0)
Dim sSeconds As Short = Split(strTime1, ".")(1) - Split(strTime2, ".")(1)
sSeconds = sMinutes * 60 + sSeconds ' Convert Value to seconds
'now convert back to minutes.seconds
sMinutes = (sSeconds - (sSeconds Mod 60)) / 60
sSeconds = (sSeconds Mod 60)
Return sMinutes & "." & sSeconds
End Function
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Dec 6th, 2003, 11:42 PM
#3
Use the TimeSpan object to work with time calculations:
VB Code:
Dim ts As New TimeSpan(0, 30, 0) 'start with 30 min
MsgBox(ts.Subtract(New TimeSpan(0, 1, 30)).ToString) 'subtract 1 min 30 sec
You can enter the time as a string too if you prefer, just use the parse shared method.
VB Code:
ts = TimeSpan.Parse("0:30:00")
MsgBox(ts.Subtract(TimeSpan.Parse("0:01:30")).ToString)
-
Jun 14th, 2004, 02:07 AM
#4
Frenzied Member
I am testing performance and comparing time concumprtions in Java and .net and for this I need to calculated in milliseconds. My timestamps are:
time1 = Now.Hour & ":" & Now.Minute & ":" & Now.Second & ":" & Now.Millisecond
when the calculation begins and
time2 = Now.Hour & ":" & Now.Minute & ":" & Now.Second & ":" & Now.Millisecond
How do I subtract the two times when I need milliseconds?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|