IBM Support

Convert 24 hour clock to a 12 hour clock

Troubleshooting


Problem

Is it possible to display a time field formatted as a 24 hour time, to a 12 hour time?

Resolving The Problem

Yes, the following steps will convert a 24 hour clock to a 12 hour clock. The names of the columns are optional, you can add meaningful names to suit your needs.


1. First convert your 24 hour time to a STRING.
2. Next, create a calculation to make this string look like a time if that is necessary (for example; 15:24:33).

Calculation name: Add [:]

Substring(<24 hour time>,1 ,2) + ':' + Substring(<24 hour time>,3 ,2) + ':'+ Substring(<24hour time>,5 ,2)


3. Then create a calculation to extract the hour from the string.

Calculation name: Get Hour

Substring(Add [:], 1, 2)

4. This calculation converts the 24 hour to a 12 hour.

Calculation name: Convert to 12 hour

If(Get Hour >= 13) Then (String-to-number(Get Hour)-12) else (String-to-number(Get Hour))

5. Add another calculation to convert A number to a string.

Calculation name: Convert number to string

Number-to-string(Convert to 12 hour)

6. Finally add all of these together.

Calculation name: Results

Convert number to string + Substring(Add [:], 3, 6) + ' ' + If(Get Hour > '12') then('pm') else ('am')

The end results should be a 12 hour time.

[{"Product":{"code":"SSTQPQ","label":"IBM Cognos Series 7 PowerPlay"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Impromptu","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Impromptu 4.01","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

65533

Document Information

Modified date:
15 June 2018

UID

swg21353014