Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query DateTimeZone.ToText: How to Use It

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

DateTimeZone.ToText converts a datetimezone value into a text string, optionally using a format string and a culture code. The basic syntax is DateTimeZone.ToText(value, optional format, optional culture). If you omit the format, Power Query returns the value in its default ISO-like format, such as 2024-03-15T14:30:00.0000000+01:00. You need a datetimezone value and, if you want a specific layout, a valid format string. That is the whole answer; the steps below show how to apply it in the Power Query Editor and how to avoid the common traps.

What You'll Need

  • Power BI Desktop, Excel with Power Query, or another host that includes the Power Query Editor. The function is a Power Query M function, so it is not available in plain Excel formulas.
  • A column or value that is genuinely of type datetimezone. If your column is datetime or text, convert it first, or the function will return an error.
  • A format string if you want a non-default output. Format strings use the same patterns as .NET custom date and time formats, for example yyyy-MM-dd HH:mm:ss zzz.
  • A culture code if your output must follow a specific regional convention, for example "en-US" or "de-DE". This is optional.

Step-by-Step

  1. Open the Power Query Editor. In Power BI Desktop, select Transform data on the Home ribbon. In Excel, go to Data > Get Data > Launch Power Query Editor. Menu labels can differ slightly by version, device and region.
  2. Load or select the query that contains your datetimezone column. You can apply the function to an existing column or create a new custom column.
  3. Check the column type. Select the column header. The type icon should show a date and time with a time zone indicator. If the icon shows only a date or a plain date and time, the column is not datetimezone. Use Transform > Data Type and choose Date/Time/Timezone to convert it. If the conversion fails, the source text does not contain a valid offset.
  4. For a new column, choose Add Column > Custom Column. Give the column a name, then enter a formula such as DateTimeZone.ToText([OrderTime]). Replace [OrderTime] with your actual column name.
  5. To replace the existing column instead, right-click the column header and choose Replace Values, or use Transform > Replace Values. In the dialog, enter the M expression that calls the function, or use the formula bar to edit the step directly. Replacing the column loses the original datetimezone type, so keep a duplicate if you still need the timestamp for sorting or filtering.
  6. Add a format string if you need a specific layout. For example, DateTimeZone.ToText([OrderTime], "yyyy-MM-dd HH:mm:ss zzz") returns a string like 2024-03-15 14:30:00 +01:00. The zzz token is the offset from UTC. Use zz for a shorter offset such as +01, and K for a round-trip offset.
  7. Add a culture code when the output must follow a regional format. For example, DateTimeZone.ToText([OrderTime], "dd/MM/yyyy HH:mm", "en-GB"). The culture affects month names, day names and separators, not the offset itself.
  8. Press OK and review the result. The new column is text. If you see errors, select the error cell to read the message; the usual cause is a value that is not datetimezone or a format string with an invalid token.
  9. Rename the column and set the data type to Text. Power Query may infer the type automatically, but confirm it on the Home or Transform tab. A text column will not sort chronologically, so keep a separate datetimezone column if you need time-based sorting.
  10. Apply and close. Select Close & Apply to load the result into your data model or worksheet.

Common Mistakes

  • Passing a datetime column. DateTimeZone.ToText expects datetimezone. A plain datetime value returns an error. Convert the column type first, or use DateTime.ToText for datetime values.
  • Using Excel-style format codes. Power Query uses .NET custom format strings. Codes such as mm for minutes and MM for months are case-sensitive; swapping them produces the wrong output without an error.
  • Forgetting the offset token. A format without zzz, zz or K drops the time zone from the output, which can make timestamps ambiguous.
  • Assuming the culture changes the offset. The culture code changes names and separators only. The offset comes from the stored datetimezone value.
  • Replacing the original column and losing sortability. Text sorts alphabetically. Keep a datetimezone copy for ordering and filtering.
  • Expecting the function to convert time zones. DateTimeZone.ToText formats the value; it does not shift it. Use DateTimeZone.SwitchZone or DateTimeZone.ToLocal first if you need a different zone.

Tips

  • Use the o format specifier for a round-trip string that preserves full precision and the offset.
  • Test your format string on a single value in a Custom Column before applying it to a whole column.
  • If you need a consistent machine-readable output, the default format is already ISO 8601-like and sorts correctly as text.
  • Use Text.From only for simple conversions; DateTimeZone.ToText gives you control over the layout.
  • Document the format string in the query step name so future editors know why the column looks the way it does.

Troubleshooting

  • Error: We cannot convert the value to type DateTimeZone. The column is not datetimezone. Change the data type, or check the source text for a missing offset.
  • Output shows the wrong month or minute. Check the case of MM versus mm in your format string.
  • Offset missing from the output. Add zzz or K to the format string.
  • Culture code has no effect. Confirm the code is a valid culture name and that your format string actually contains culture-sensitive tokens such as month or day names.
  • The column still behaves like a date. Set the data type to Text explicitly after the conversion step.
  • If that did not work, duplicate the query, remove the custom step, and rebuild it one argument at a time to isolate which argument causes the error.

Frequently Asked Questions

What is the difference between DateTimeZone.ToText and DateTime.ToText?

DateTimeZone.ToText works on values that include a time zone offset and can output that offset. DateTime.ToText works on values without an offset. Using the wrong one returns a type error.

Can I convert a datetimezone value to a different time zone and then to text?

Yes. Apply DateTimeZone.SwitchZone first, then wrap the result in DateTimeZone.ToText. The function itself only formats; it does not shift the zone.

Is the culture argument required?

No. It is optional. Omit it when the default format is acceptable or when you use a format string that does not depend on culture.

Why does my output not sort chronologically?

Because the result is text. Keep a datetimezone column for sorting, or use a format such as yyyy-MM-dd HH:mm:ss zzz that sorts correctly as text.

Does DateTimeZone.ToText work in Excel Power Query?

Yes, it is an M function available in the Power Query Editor in Excel as well as in Power BI Desktop. It is not available as a worksheet formula.

What happens if the format string contains an invalid token?

Power Query returns an error for that row. Select the error to see the message, then correct the format string.