Duration.FromText
DurationConverts a text representation to a duration value.
Syntax
Duration.FromText(text as nullable text) as nullable durationParameters
| Name | Type | Required | Description |
|---|---|---|---|
text | text | Yes | A text string representing a duration in the format "D.HH:MM:SS" or "HH:MM:SS" (e.g., "1.02:30:00" for 1 day, 2 hours, 30 minutes). |
Return Value
duration — A duration value parsed from the given text, or null if the input is null.
Remarks
Duration.FromText parses a text value in the format "D.HH:MM:SS" (days, hours, minutes, seconds) or "HH:MM:SS" (when days are zero) into a duration value. This is the inverse of Duration.ToText. The day component (the D. prefix) is optional and may be omitted for durations shorter than one day. Fractional seconds are also supported.
If the text is null, the function returns null. If the text cannot be parsed — for example, it contains an unexpected format or non-numeric characters — the function raises an error. Use try Duration.FromText(...) otherwise null to handle malformed data without stopping the query.
A typical source of text-format durations is systems that serialize duration values to string for storage or transport (such as ISO 8601 PTxHxMxS strings — note that M uses its own D.HH:MM:SS format, not ISO 8601). You will need to reformat ISO 8601 duration strings before passing them to Duration.FromText.
Examples
Example 1: Parse duration text values in M format
#table(
type table [DurationText = text, Parsed = duration],
{
{"1.04:45:00", Duration.FromText("1.04:45:00")},
{"1.21:45:00", Duration.FromText("1.21:45:00")},
{"00:15:30", Duration.FromText("00:15:30")}
}
)DurationText | Parsed | |
|---|---|---|
| 1 | 1.04:45:00 | 1.04:45:00 |
| 2 | 1.21:45:00 | 1.21:45:00 |
| 3 | 00:15:30 | 0.00:15:30 |
Example 2: Parse a specific duration text value
#table(
type table [DurationText = text, Parsed = duration],
{{"1.02:30:00", Duration.FromText("1.02:30:00")}}
)DurationText | Parsed | |
|---|---|---|
| 1 | 1.02:30:00 | 1.02:30:00 |
Example 3: Safe parsing with try...otherwise for mixed data
#table(
type table [DurationText = text, Parsed = duration],
{
{"1.04:45:00", try Duration.FromText("1.04:45:00") otherwise null},
{"invalid", try Duration.FromText("invalid") otherwise null},
{"0.17:45:00", try Duration.FromText("0.17:45:00") otherwise null}
}
)DurationText | Parsed | |
|---|---|---|
| 1 | 1.04:45:00 | 1.04:45:00 |
| 2 | invalid | null |
| 3 | 0.17:45:00 | 0.17:45:00 |