Time.ToText

Time

Converts a time value to a text string.

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

Syntax

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

Parameters

NameTypeRequiredDescription
timetimeYesThe time value to convert to text.
optionsanyNoA record or culture text string. Supported record fields: Format (custom format string, e.g., "HH:mm") and Culture (e.g., "en-US").

Return Value

textA text representation of the time, or null if the input is null.

Remarks

Time.ToText formats a time value as a text string. Without options, it produces a 24-hour string such as "14:30:00". Use the Format field in the options record to apply custom patterns such as "h:mm tt" (12-hour with AM/PM) or "HH:mm" (24-hour without seconds). The Culture field controls locale-specific formatting for AM/PM designators and other locale-sensitive specifiers. Format strings follow .NET custom time format conventions.

Always specify Culture when using locale-sensitive specifiers such as tt (AM/PM designator). Without an explicit Culture, the AM/PM text and time-separator character may vary between Power BI Desktop and Power BI Service cloud refresh depending on the host machine's locale. Use "en-US" for consistent English output.

If the input is null, the function returns null. To format a full datetime including the time, use DateTime.ToText. To format only the date component, use Date.ToText.

Examples

Example 1: Format log timestamps as 12-hour AM/PM time strings

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(OrderLog, 4), {"LogID", "Timestamp"}),
    "TimeDisplay",
    each Time.ToText(Time.From([Timestamp]), [Format="h:mm tt", Culture="en-US"]),
    type text
)
Result
LogID
Timestamp
TimeDisplay
1L0011/15/2024 9:30:00 AM9:30 AM
2L0021/16/2024 2:15:00 PM2:15 PM
3L0031/18/2024 11:00:00 AM11:00 AM
4L0041/20/2024 8:45:00 AM8:45 AM

Example 2: Format a specific time value

#table(
    type table [Time = time, Formatted = text],
    {{#time(14, 30, 0), Time.ToText(#time(14, 30, 0), [Format="HH:mm", Culture="en-US"])}}
)
Result
Time
Formatted
114:30:0014:30

Example 3: Format times with multiple patterns for different audiences

#table(
    type table [Time = time, Format12h = text, Format24h = text],
    {
        {#time(9, 30, 0),  Time.ToText(#time(9, 30, 0),  [Format="h:mm tt", Culture="en-US"]), Time.ToText(#time(9, 30, 0),  [Format="HH:mm", Culture="en-US"])},
        {#time(14, 15, 0), Time.ToText(#time(14, 15, 0), [Format="h:mm tt", Culture="en-US"]), Time.ToText(#time(14, 15, 0), [Format="HH:mm", Culture="en-US"])},
        {#time(0, 0, 0),   Time.ToText(#time(0, 0, 0),   [Format="h:mm tt", Culture="en-US"]), Time.ToText(#time(0, 0, 0),   [Format="HH:mm", Culture="en-US"])}
    }
)
Result
Time
Format12h
Format24h
109:30:009:30 AM09:30
214:15:002:15 PM14:15
300:00:0012:00 AM00:00

Compatibility

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