Formatting the Duration data type
Who is this article for?Users who need more information about the 'Duration' data type.
PI_Update dataor higher permissions are required.
Duration PI is a data type designed to record the length of time - for example, how long a phone call lasted - not the time of day. This article will provide you with some additional information to help you understand how to best utilise this data type.
In this article:
1. Entering data
Data for this data type can be entered manually into the system or imported using the PI import spreadsheet.
All data must be in a form which the system can recognise. We’ve tried to make the parser as lenient as possible.
The following forms are accepted:
| Form | Explanation |
|---|---|
| 10 | A number by itself is assumed to be seconds |
| 5 30 | Two numbers without any other markers are assumed to be minutes and seconds, in this instance 5 minutes 30 seconds |
| 3m45 | Interpreted as 3 minutes and 45 seconds |
| 1h | Interpreted as 1 hour |
| 1h35m13s | Interpreted as 1 hour 35 minutes and twelve seconds |
| 1 h 23 m | You can include spaces anywhere in the input strings |
| 500ms | Milliseconds are identified with ms |
| 12 40 15 | Three numbers are assumed to be hours, minutes and seconds: 12h 40m 15s |
| 1 2 3 4 | Four numbers is equivalent to 1h 2m 3s 4ms |
| 1h 30s | You can omit minutes: 1 hour and 30 seconds |
| 99m | You can enter more minutes than there are in an hour. This will become 1h 39m |
| 99m 99s | This will correct itself to 1h 40m 39s |
To input a negative duration, start your input string with a '-' (minus) symbol.
2. Formatting data
You can format 'Duration' data as you see fit, however, the format string for a Duration PI works a little differently to other format strings.
This is because there are four number components of a Duration PI: hours, minutes, seconds, and milliseconds. Each of these number components is represented by one of the following tokens:
| Form | Explanation |
|---|---|
| [hh] | Hours, with a leading zero |
| [h] | Hours without leading zeroes |
| [mm] | Minutes with leading zeroes |
| [m] | Minutes without leading zeroes |
| [ss] | Seconds with leading zeroes |
| [s] | Seconds without leading zeroes |
| [millis] | Milliseconds with two leading zeroes |
You can use these tokens alongside other text to style the output.
Below are some scenarios to get you started:
- Show only seconds and milliseconds: [s]s [millis]ms.
- Show only hours and minutes: [h]h [mm]m or [h] hours [m] minutes for a longer variant.
-
Show only hours: [h].
This will not display a decimal or fractional amount of time for the loss of precision of this format, nor will it round up or down. It will only display a '1' once the duration is longer than 1 hour, and a '2' once the duration is longer than two hours.
By default, the format applied is: [h]h [mm]m [ss]s. You don’t have to enter a duration in terms of its format.
Durations cannot be longer than about one million hours. That’s 114 years, so it should be plenty!