Time.ToText
TimeConverts a time value to a text string.
Syntax
Time.ToText(time as nullable time, optional options as any) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
time | time | Yes | The time value to convert to text. |
options | any | No | A record or culture text string. Supported record fields: Format (custom format string, e.g., "HH:mm") and Culture (e.g., "en-US"). |
Return Value
text — A 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
)LogID | Timestamp | TimeDisplay | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | 9:30 AM |
| 2 | L002 | 1/16/2024 2:15:00 PM | 2:15 PM |
| 3 | L003 | 1/18/2024 11:00:00 AM | 11:00 AM |
| 4 | L004 | 1/20/2024 8:45:00 AM | 8: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"])}}
)Time | Formatted | |
|---|---|---|
| 1 | 14:30:00 | 14: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"])}
}
)Time | Format12h | Format24h | |
|---|---|---|---|
| 1 | 09:30:00 | 9:30 AM | 09:30 |
| 2 | 14:15:00 | 2:15 PM | 14:15 |
| 3 | 00:00:00 | 12:00 AM | 00:00 |