Time.FromText
TimeConverts a text representation of a time to a time value.
Syntax
Time.FromText(text as nullable text, optional options as any) as nullable timeParameters
| Name | Type | Required | Description |
|---|---|---|---|
text | text | Yes | A text string representing a time, such as "14:30:00" or "2:30 PM". |
options | any | No | A record or culture text string. Supported record fields: Format (custom format string, e.g., "HH:mm:ss") and Culture (e.g., "en-US"). |
Return Value
time — A time value parsed from the given text, or null if the input is null.
Remarks
Time.FromText parses a text value into a time. Without options, it attempts common 24-hour formats such as "HH:mm:ss" or "HH:mm". Use the options record to supply a custom Format pattern or a Culture for locale-specific strings such as "2:30 PM". Format strings follow .NET custom time format conventions.
Always specify both Format and Culture when parsing locale-specific strings. Without Culture, parsing depends on the host machine's locale, which can produce different results in Power BI Desktop vs. Power BI Service. Use "en-US" as a consistent default for English input.
If the text is null, the function returns null. If parsing fails, the function raises an error. Use try Time.FromText(...) otherwise null to handle malformed data rows gracefully without stopping the query.
Examples
Example 1: Parse 24-hour time strings
#table(
type table [TextTime = text, Parsed = time],
{
{"09:30:00", Time.FromText("09:30:00")},
{"14:15:00", Time.FromText("14:15:00")},
{"08:45:00", Time.FromText("08:45:00")}
}
)TextTime | Parsed | |
|---|---|---|
| 1 | 09:30:00 | 09:30:00 |
| 2 | 14:15:00 | 14:15:00 |
| 3 | 08:45:00 | 08:45:00 |
Example 2: Parse a 12-hour format time string
#table(
type table [TextTime = text, Parsed = time],
{{"02:30:00 PM", Time.FromText("02:30:00 PM", [Format="hh:mm:ss tt", Culture="en-US"])}}
)TextTime | Parsed | |
|---|---|---|
| 1 | 02:30:00 PM | 14:30:00 |
Example 3: Safe parsing with try...otherwise for mixed data
#table(
type table [TextTime = text, Parsed = time],
{
{"09:30:00", try Time.FromText("09:30:00") otherwise null},
{"N/A", try Time.FromText("N/A") otherwise null},
{"14:15:00", try Time.FromText("14:15:00") otherwise null}
}
)TextTime | Parsed | |
|---|---|---|
| 1 | 09:30:00 | 09:30:00 |
| 2 | N/A | null |
| 3 | 14:15:00 | 14:15:00 |