Time.FromText

Time

Converts a text representation of a time to a time value.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Time.FromText(text as nullable text, optional options as any) as nullable time

Parameters

NameTypeRequiredDescription
texttextYesA text string representing a time, such as "14:30:00" or "2:30 PM".
optionsanyNoA 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

timeA 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")}
    }
)
Result
TextTime
Parsed
109:30:0009:30:00
214:15:0014:15:00
308:45:0008: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"])}}
)
Result
TextTime
Parsed
102:30:00 PM14: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}
    }
)
Result
TextTime
Parsed
109:30:0009:30:00
2N/Anull
314:15:0014:15:00

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks