Duration.ToText
DurationConverts a duration value to its text representation.
Syntax
Duration.ToText(duration as nullable duration) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
duration | duration | Yes | The duration value to convert to text. |
Return Value
text — A text string in the format "D.HH:MM:SS" representing the duration, or null if the input is null.
Remarks
Duration.ToText formats a duration value as a text string using the format "D.HH:MM:SS" (days, hours, minutes, seconds). Durations shorter than one day omit the day prefix (e.g., "02:30:00"). Fractional seconds are included when present. This function is the inverse of Duration.FromText and produces the canonical M duration text representation.
If the input is null, the function returns null. The output format is not localized — it always uses . as the day separator and : between time components, regardless of the host culture. This makes it safe for serialization, logging, and round-tripping through Duration.FromText.
Note that the output format (D.HH:MM:SS) is not the same as ISO 8601 duration format (PTxHxMxS). If you need ISO 8601 output, you will need to construct it manually using Duration.Days, Duration.Hours, Duration.Minutes, and Duration.Seconds.
Examples
Example 1: Display duration values as text for a report
Table.AddColumn(
Table.SelectColumns(
Table.SelectRows(OrderLog, each [DurationMinutes] <> null),
{"LogID", "DurationMinutes"}
),
"DurationText",
each Duration.ToText(#duration(0, 0, [DurationMinutes], 0)),
type text
)LogID | DurationMinutes | DurationText | |
|---|---|---|---|
| 1 | L002 | 1,725 | 1.04:45:00 |
| 2 | L004 | 2,745 | 1.21:45:00 |
| 3 | L006 | 1,065 | 0.17:45:00 |
| 4 | L008 | 2,670 | 1.20:30:00 |
Example 2: Convert a specific duration to text
#table(
type table [Duration = duration, AsText = text],
{{#duration(3, 5, 30, 0), Duration.ToText(#duration(3, 5, 30, 0))}}
)Duration | AsText | |
|---|---|---|
| 1 | 3.05:30:00 | 3.05:30:00 |
Example 3: Round-trip a duration through text and back
let
Original = #duration(1, 4, 45, 0),
AsText = Duration.ToText(Original),
BackToDuration = Duration.FromText(AsText)
in
#table(
type table [Original = duration, AsText = text, Recovered = duration],
{{Original, AsText, BackToDuration}}
)The final output — a one-row table showing the original duration, its text form, and the recovered duration after round-tripping through text.
Original | AsText | Recovered | |
|---|---|---|---|
| 1 | 1.04:45:00 | 1.04:45:00 | 1.04:45:00 |