Downloads
Power Query MDate and timeBeginner

DateTime.ToText

Formats a date and time as text using a format string, such as "yyyy-MM-dd HH:mm".

Syntax
DateTime.ToText(dateTime as nullable datetime, optional format as nullable text, optional culture as nullable text) as nullable text

Returns: The formatted text, or null when the input is null.

What it does

DateTime.ToText turns a timestamp into text in a layout you choose. Use it to make a readable label for a report, a file name that carries a time, or a log line. The format string sets the layout. HH is the 24 hour clock hour and hh is the 12 hour clock hour, so pick the one your readers use.

Syntax and arguments

Example

A reconciliation log names each file by the time it was produced, so that two runs on the same day can be told apart.

let
    Produced = #datetime(2026, 10, 29, 14, 30, 0),
    FileName = "recon_" & DateTime.ToText(Produced, "yyyyMMdd_HHmm", "en-US") & ".csv",
    Readable = DateTime.ToText(Produced, "yyyy-MM-dd HH:mm", "en-US")
in
    {FileName, Readable}

The file name is "recon_20261029_1430.csv" and the readable label is "2026-10-29 14:30". The 24 hour clock keeps 14:30 unambiguous, which matters when a second run is made later the same day.

Example: a second, different use

Make a label with a 12 hour clock and AM or PM for a memo that goes to a person who reads that style, with the format "hh:mm tt".

Things to watch

In business terms

Audit logs, file names and report stamps need a timestamp that reads the same way on every system. A fixed format gives the reviewer a time that can be sorted and checked.

Related functions

All Power Query M functions · View as Markdown · M basics