<!-- https://learnsql.cpetoday.com/functions/m/datetime-totext -->
# DateTime.ToText

Language: Power Query M
Category: Date and time
Syntax: DateTime.ToText(dateTime as nullable datetime, optional format as nullable text, optional culture as nullable text) as nullable text
Summary: Formats a date and time as text using a format string, such as "yyyy-MM-dd HH:mm".
Returns: The formatted text, or null when the input is null.
Level: Beginner
Related: Date.ToText, DateTime.From, DateTime.Time, Text.From, Text.Format

## 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
- dateTime: the datetime to format.
- format (optional): a format string. "yyyy-MM-dd HH:mm" gives a 24 hour time to the minute. "yyyy-MM-dd hh:mm tt" gives a 12 hour time with AM or PM.
- culture (optional): the culture for names and the AM and PM marks, such as "en-US".
## 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.

```powerquery
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
- MM is the month and mm is the minute, so the letters must be exact.
- HH and hh are different: one is the 24 hour clock, the other the 12 hour clock.
- Without a format the default depends on the machine's culture.
- The result is text. Keep the datetime column for any calculation.
- Null in gives null out.
## 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.
