Today I was building some Access DB, where I had to sum two variables in HH:MM:SS format. Then I had to multiply them by one integer and at the end to display them as HH:MM:SS once again.
It seems really easy, if you are programmer who uses plenty of external libraries, but with VBA you need some time to make sure it runs smoothly. Actually, the reason I write this article (as plenty of the articles in this blog) is simply to have it available for me. Not that I do not have a GitHub profile, but this way is fancier.
So, this is how the VBA code looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Const MINUTES_IN_ONE_DAY = 1440 Sub Test() Dim Multiplier As Integer Dim datFirst As Date Dim datSecond As Date datFirst = "00:02:00" datSecond = "00:05:00" Multiplier = 3 intinput = ((CDate(datFirst) + CDate(datSecond)) * MINUTES_IN_ONE_DAY) * Multiplier intinput = Format(Int(intinput / 3600), "00") & ":" & Format(Int((intinput - (Int(intinput / 3600) * 3600)) / 60), "00") & ":" & Format(((intinput Mod 60)), "00") Debug.Print intinput End Sub |
So pretty much, if you have as input datFirst = 00:02:00 and datSecond = 00:05:00 and Multiplier = 3 at the end of our test we would have 00:21:00 printed in the console. It is useful and as easy as it seems 🙂
Enjoy it !