Micro Focus QTP (UFT) Forums
How to change 24 hrs time format to 12 hrs time format - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to change 24 hrs time format to 12 hrs time format (/Thread-How-to-change-24-hrs-time-format-to-12-hrs-time-format)



How to change 24 hrs time format to 12 hrs time format - Varsha Gupta - 04-20-2018

Hi All, 

I would like to convert following 24 hrs time to 12 hrs format using UFT 12.5.

Time: 1430

expected to show as: 2:30

Please do the needful.

Thank you.


RE: How to change 24 hrs time format to 12 hrs time format - Ankur - 04-21-2018

It can be done using several ways by using custom functions or built in functions in VB Script.

If the time is always in this format hhmm, you just need to introduce a colon : between hh & mm and pass the result to TimeValue built in function.

Here is how:


Code:
Dim t24hr, t12hr

t24hr = "1430"
t24hr = Replace(t24hr, Right(t24hr,2), ":" & Right(t24hr,2))

t12hr = TimeValue(t24hr)

msgbox t12hr