Language basics / Type conversions |
Interval formatting occurs when converting a INTERVAL to a string, for example in a LET, DISPLAY or PRINT instruction, and when displaying interval values in form fields.
[+|-]yyyy-mm
[+|-]dddd hh:mm:ss.fffff
The next example formats a INTERVAL value by using the util.Interval.format() method:
IMPORT util MAIN DEFINE iv INTERVAL DAY(6) TO MINUTE LET iv = "-157 11:23" DISPLAY util.Interval.format(iv, "%d %H:%M") END MAIN
-157 11:23
And interval value can be formatted with the util.Interval.format() method.
DEFINE iv INTERVAL HOUR(6) TO FRACTION(5) LET iv = "20234:34:56.82373"
DEFINE iv INTERVAL DAY(6) TO FRACTION(5) LET iv = util.Interval.parse( "-7467 + 23:45:34.12345", "%d + %H:%M:%S%F5" )
When formatting INTERVAL values, the format-string of the util.Interval.parse() and util.Interval.format() methods consists of a set of place holders that represent the different parts of a interval value (year, month, day, hour, minute, second and fraction).
Table 1 shows the formatting symbols for INTERVAL expressions. Any character different from the placeholders described in this table is interpreted as a literal and will appear as-is in the resulting string.
Placeholder | Description |
---|---|
%Y | Years (0-999999999) |
%m | Month (00-11) or (0-999999999) |
%d | Days (0-999999999) |
%H | Hours (00-23) or (0-999999999) |
%M | Minutes (00-59) or (0-999999999) |
%S | Secondes (00-59) or (0-999999999) |
%F[n] | The fractional part of a second, where n specifies the number of digits in the fractional part (1 to 5) |
%t | A tab character |
%n | A newline character |
Format String | Interval value | Result string |
---|---|---|
%d days %H:%M | 54561 11:23 | 54561 days 11:23 |
%d days %H:%M:%S%F5 | 54561 11:23:45.12345 | 54561 days 11:23:45.12345 |
[%Y years and %m months] | 1023-03 | [1023 years and 03 months] |