• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[VB6] Time Diff

Status
Not open for further replies.
Level 13
Joined
Jul 16, 2012
Messages
679
Hello fellas!

I want to know how to get a Hour, Minutes, and Seconds

Code:
        Dim lSeconds, lMinutes As Long
        Dim sTimeDiff As String

        lSeconds = DateDiff("s", TimeStart, TimeEnd)
        lMinutes = Fix(lSeconds / 60) '// Gets the whole number (not rounded)
        lSeconds = ((lSeconds / 60) - lMinutes) * 60 '// get the remaining seconds
        sTimeDiff = "00:" & Format$(lMinutes, "00") & ":" & Format$(lSeconds, "00")
stackoverflow.com's Source Code

So the problem is, I don't know how to get the hour
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You repeat the break down process on lMinutes. I think this would work...
Code:
       Dim lSeconds, lMinutes As Long
        Dim sTimeDiff As String

        lSeconds = DateDiff("s", TimeStart, TimeEnd)
        lMinutes = Fix(lSeconds / 60) '// Gets the whole number (not rounded)
        lSeconds = ((lSeconds / 60) - lMinutes) * 60 '// get the remaining seconds
        lHours = Fix(lMinutes / 60) '// Gets the whole number (not rounded)
        lMinutes = ((lMinutes / 60) - lHours) '// get the remaining minutes
        sTimeDiff = Format$(lHours, "00") & ":" & Format$(lMinutes, "00") & ":" & Format$(lSeconds, "00")
Never used Visual Basic so I have no idea if better approaches exist. For example the modulus operator would simplify the code but I do not know it the language has one.
 
Status
Not open for further replies.
Top