Search code examples
vb6datetimepicker

Need direction on writing custom datetime formatting in VB6


I have a string:

A -DDD HH:MM:SS

and currently trying to write a function that will take in this string and also the format to convert it to. For example, say I wanted to display just the HH:MM ss (Hours with leading Zeros + colon + Minutes with leading Zeros + no colons + seconds without leading Zeros.

I understand for VB6 you'd probably use a string function like Mid(str, int, int) to get the time portion. But if I create a custom format of

HH:MM ss

How would you approach formating this?

J


Solution

  • Chop off the strictly formatted time part and use the format function;

    s = "A -??? 12:34:56"
    t = right$(s,8)
    
    ?format$(t, "HH:NN ss")
    12:34 56
    
    ?format$(t, "HH:NN ss AM/PM")
    12:34 56 PM
    
    ?format$(t, "H, N, S  AM/PM")
    12, 34, 56  PM
    

    (N is minute here)