DateTime.ToText
DateTimeConverts a datetime value to a text string.
Syntax
DateTime.ToText(dateTime as nullable datetime, optional options as any) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | datetime | Yes | The datetime value to convert to text. |
options | any | No | A record or culture text string. Supported record fields: Format (custom format string, e.g., "yyyy-MM-dd HH:mm:ss") and Culture (e.g., "en-US"). |
Return Value
text — A text representation of the datetime, or null if the input is null.
Remarks
DateTime.ToText formats a datetime value as a text string. Without options, it produces an ISO 8601-style string such as "2024-03-15T14:30:00". Use the Format field in the options record to apply custom patterns such as "dd/MM/yyyy HH:mm" or "MMMM d, yyyy h:mm tt". The Culture field controls locale-specific formatting such as localized month names (MMMM) and AM/PM designators (tt). Format strings follow .NET custom datetime format conventions.
Always specify Culture when using locale-sensitive format specifiers such as MMMM (full month name) or dddd (full day name). Without an explicit Culture, the result depends on the host machine's locale, which can produce different output in Power BI Desktop vs. Power BI Service cloud refresh. Use "en-US" as a safe default for English output.
If the input is null, the function returns null. To format date-only values, use Date.ToText. To format datetimezone values including the offset, use DateTimeZone.ToText.
Examples
Example 1: Format datetime values for a report label
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(OrderLog, 4),
{"LogID", "Timestamp"}
),
"DisplayTime",
each DateTime.ToText([Timestamp], [Format="MMMM d, yyyy h:mm tt", Culture="en-US"]),
type text
)LogID | Timestamp | DisplayTime | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | January 15, 2024 9:30 AM |
| 2 | L002 | 1/16/2024 2:15:00 PM | January 16, 2024 2:15 PM |
| 3 | L003 | 1/18/2024 11:00:00 AM | January 18, 2024 11:00 AM |
| 4 | L004 | 1/20/2024 8:45:00 AM | January 20, 2024 8:45 AM |
Example 2: Format in 24-hour ISO style
#table(
type table [DateTime = datetime, ISO = text],
{{#datetime(2024, 3, 15, 14, 30, 0), DateTime.ToText(#datetime(2024, 3, 15, 14, 30, 0), [Format="yyyy-MM-dd HH:mm:ss", Culture="en-US"])}}
)DateTime | ISO | |
|---|---|---|
| 1 | 3/15/2024 2:30:00 PM | 2024-03-15 14:30:00 |
Example 3: Format with date and abbreviated time for compact display
Table.AddColumn(
Table.SelectColumns(Table.FirstN(OrderLog, 4), {"LogID", "Timestamp"}),
"ShortLabel",
each DateTime.ToText([Timestamp], [Format="dd-MMM HH:mm", Culture="en-US"]),
type text
)LogID | Timestamp | ShortLabel | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | 15-Jan 09:30 |
| 2 | L002 | 1/16/2024 2:15:00 PM | 16-Jan 14:15 |
| 3 | L003 | 1/18/2024 11:00:00 AM | 18-Jan 11:00 |
| 4 | L004 | 1/20/2024 8:45:00 AM | 20-Jan 08:45 |