Convert Number To Time

Category:
Dates and Math
Type:
Snippets
Difficulty:
Beginning
Author:
Brian matumbura

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
Ever wondered how you can convert a Number (integer, long, double, ...) representing Seconds, Minutes, Hours or some other unit of time or date? Instead of using the VB operators Mod and Div to represent the Number as a formated time, you can easily use the Format() and DateAdd() functions. The sample function below converts a Number representing Seconds into a formated time. You can also replace the "s" in the formula with "h" or "m" to convert numbers representing Hours and Minutes respectively to time.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: