DateTime.ToText

DateTime

Converts a datetime 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

DateTime.ToText(dateTime as nullable datetime, optional options as any) as nullable text

Parameters

NameTypeRequiredDescription
dateTimedatetimeYesThe datetime value to convert to text.
optionsanyNoA 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

textA 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
)
Result
LogID
Timestamp
DisplayTime
1L0011/15/2024 9:30:00 AMJanuary 15, 2024 9:30 AM
2L0021/16/2024 2:15:00 PMJanuary 16, 2024 2:15 PM
3L0031/18/2024 11:00:00 AMJanuary 18, 2024 11:00 AM
4L0041/20/2024 8:45:00 AMJanuary 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"])}}
)
Result
DateTime
ISO
13/15/2024 2:30:00 PM2024-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
)
Result
LogID
Timestamp
ShortLabel
1L0011/15/2024 9:30:00 AM15-Jan 09:30
2L0021/16/2024 2:15:00 PM16-Jan 14:15
3L0031/18/2024 11:00:00 AM18-Jan 11:00
4L0041/20/2024 8:45:00 AM20-Jan 08:45

Compatibility

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