Power Query Time.ToText: Convert Times to Text
In this article
Time.ToText converts a time value in Power Query into a text string, and the fastest version is Time.ToText(#time(14, 30, 0)), which returns "2:30 PM" using your locale's default format. You can also pass an optional format string and culture code to control the output exactly, for example Time.ToText(#time(14, 30, 0), "HH:mm") to get "14:30". Nothing needs installing: the function is built into Power Query in Excel, Power BI Desktop and Dataflows, so you only need a query that already contains a time column or a time value.
What You'll Need
- Power Query open in Excel (Data > Get Data), Power BI Desktop (Transform data), or another host that runs the Power Query engine. Menu labels vary slightly by version, device and region.
- A column or value of type Time. If your column is text or date/time, convert it first with the type icon in the column header or with Date.From / DateTime.Time.
- A destination for the result: a new custom column, or a step in the formula bar.
Step-by-Step
- Load your data into the Power Query Editor. Confirm the column you want to convert shows the time icon (a small clock) in its header. If it shows ABC or a calendar icon, click the icon and choose Time before continuing.
- Select the column header, then go to Add Column > Custom Column so the original column stays intact. (Using Transform instead overwrites the source column, which is harder to undo later.)
- In the Custom Column dialog, give the new column a name, such as TimeText.
- Enter the formula in the box. The simplest form is
Time.ToText([TimeColumn]), replacing TimeColumn with your actual column name. Column names with spaces need square brackets and quotes:Time.ToText([#"Start Time"]). - To control the output, add a format string as the second argument. Common patterns:
"hh:mm"for 12-hour with leading zero,"h:mm tt"for 12-hour with AM/PM,"HH:mm"for 24-hour, and"HH:mm:ss"to include seconds. Note that in Power Query format strings, lowercase hh is 12-hour and uppercase HH is 24-hour, the opposite of some other tools. - Add a culture code as the third argument when the default does not match your audience, for example
Time.ToText([TimeColumn], "HH:mm", "en-GB"). The culture affects separators and AM/PM designators. - Click OK. Check the new column: the icon should show ABC because the result is text. If you see Error in any row, the source value is probably null or not a real time.
- Handle nulls by wrapping the call:
if [TimeColumn] = null then null else Time.ToText([TimeColumn], "HH:mm"). This keeps blanks blank instead of turning them into errors. - Rename the column if needed, then use Home > Close & Load (or Close & Apply) to push the result back to Excel or the data model.
Common Mistakes
- Using the wrong case in the format string. "hh:mm" and "HH:mm" produce different results. Test one row before applying to the whole column.
- Passing a date/time column to Time.ToText. A DateTime value will not convert cleanly. Extract the time part first with DateTime.Time([Column]) and then convert.
- Forgetting the quotes around the format. The second argument must be text, so
Time.ToText([Col], HH:mm)fails; it needs"HH:mm". - Expecting the result to stay a time. The output is text, so sorting and date arithmetic no longer work on it. Keep a typed copy of the original column if you still need to sort chronologically.
- Ignoring nulls. A single null in the column turns into an Error value that can break downstream steps. Guard with an if statement.
- Assuming the format string is identical to Excel's cell formatting. Power Query uses its own pattern rules, so copy-pasting a custom number format from a cell often gives unexpected output.
Tips
- Use the formula bar to edit an existing step rather than rebuilding the column; it is faster and keeps step names readable.
- Build the format string in a small test query with a single #time value so you can see the result immediately.
- For dashboards, prefer 24-hour formats ("HH:mm") because they sort correctly as text and avoid AM/PM ambiguity across regions.
- If you only need to display a time nicely in a report, consider leaving the column as Time and formatting it in the visual or cell instead of converting to text. Text conversion is best when the value must be concatenated, exported or matched against text keys.
- Document the culture code you used in a comment or step name so future editors know why the output looks the way it does.
Troubleshooting
If every row shows Error, the column is almost certainly not typed as Time. Click the type icon in the header and set it to Time, then refresh the step. If only some rows fail, filter for errors and inspect the source values; blanks, text like "n/a" and values imported as numbers are the usual culprits.
If the output looks wrong rather than broken, check the format string case and the culture argument. A 12-hour pattern with no AM/PM designator will produce times that look identical for morning and afternoon. If a step worked before and now returns errors after a refresh, the source data type may have changed upstream; reapply the type conversion and confirm the column name has not been renamed.
If the custom column dialog rejects your formula, verify the column reference uses the exact name shown in the header, including the #"..." quoting for names with spaces or special characters. Finally, if the query is slow, avoid converting very large text columns repeatedly; do the conversion once in a single step rather than nesting it inside other expressions.
Frequently Asked Questions
What does Time.ToText return if I give it no format?
It returns a text version of the time using the query's default culture, typically a 12-hour format with AM/PM in US English. Supply a format string if you need something predictable across machines.
Can I convert a duration instead of a time?
No. Duration values use Duration.ToText. Passing a duration to Time.ToText will not give the result you expect.
Why is my output showing 24-hour time when I asked for 12-hour?
You likely used "HH" instead of "hh". In Power Query, uppercase H is 24-hour and lowercase h is 12-hour.
Does the culture argument change the separators?
Yes. Some cultures use a different time separator and different AM/PM text, so the same format string can look different. Set the culture explicitly when the report is shared internationally.
Can I use Time.ToText inside a calculated column in the data model?
Time.ToText is a Power Query (M) function. In DAX you would use FORMAT instead. Keep the conversion in Power Query if the text is needed for export or merging.
Will the converted text sort correctly?
Only if you use a fixed-width 24-hour format such as "HH:mm:ss". Mixed 12-hour strings sort alphabetically, which puts afternoon times in the wrong place.