Smart Systems for Home

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

Power Query DateTime.AddZone: Step-by-Step Guide

· 5 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

DateTime.AddZone takes a datetime value and returns a datetimezone value by attaching a UTC offset to it. The offset is given in hours (and optionally minutes), and the original clock time is left unchanged. For example, DateTime.AddZone(#datetime(2024, 6, 1, 9, 0, 0), 2) returns 2024-06-01T09:00:00+02:00. This is useful when you have local wall-clock times from a known time zone and need to convert them to UTC or compare them with other zoned timestamps. You need Power Query in Excel, Power BI Desktop, or another host that supports M, and a datetime column or literal to work with.

What You'll Need

  • Power Query Editor open (Excel: Data > Get Data > Launch Power Query Editor; Power BI Desktop: Transform data).
  • A table or query containing a datetime column, or a datetime literal such as #datetime(2024, 6, 1, 9, 0, 0).
  • Knowledge of the UTC offset for the source time zone (for example, +2 for Central European Summer Time, -5 for Eastern Standard Time).

Step-by-Step

  1. Load your data into Power Query. Select your table and choose Data > From Table/Range (Excel) or Get Data (Power BI). The Power Query Editor opens with your query selected.
  2. Confirm the column type is Date/Time. Click the type icon in the column header and choose Date/Time. If the column is text, use Transform > Data Type > Using Locale or Change Type with a locale that matches your source format before proceeding. DateTime.AddZone expects a datetime value, not text.
  3. Add a custom column. Go to Add Column > Custom Column. Give it a name such as LocalWithZone.
  4. Enter the formula. In the formula box, type = DateTime.AddZone([YourColumn], 2) for a +2 hour offset. Replace [YourColumn] with your actual column name. The second argument is the offset in hours; use a negative number for zones west of UTC, such as -5 for EST. For offsets with minutes, use the optional third argument: DateTime.AddZone([YourColumn], 5, 30) for +5:30.
  5. Check the result type. Click OK. The new column should show values ending in +02:00 (or your chosen offset). If the column type is shown as Any, click the type icon and choose Date/Time/Timezone.
  6. Convert to UTC if needed. To compare across zones, add another custom column with = DateTimeZone.ToUtc([LocalWithZone]). This shifts the clock time to UTC while keeping the zone information.
  7. Apply and close. Select Home > Close & Load (Excel) or Close & Apply (Power BI) to load the results.

Menu labels can differ slightly by version, device, or region, but the Custom Column and data type steps are consistent across current Power Query versions.

Common Mistakes

  • Passing text instead of datetime. DateTime.AddZone requires a datetime value. If your column is text, convert it first with Change Type or DateTime.FromText. Otherwise you get an error or an unexpected result.
  • Using the wrong sign for the offset. Positive offsets are east of UTC (for example, +2 for Berlin), negative offsets are west (for example, -5 for New York). Reversing the sign shifts times in the wrong direction.
  • Forgetting minutes for half-hour zones. Zones such as India (+5:30) or Newfoundland (-3:30) need the third argument. Using only the hour argument gives an incorrect offset.
  • Expecting automatic daylight saving. DateTime.AddZone does not look up time zone rules; it simply attaches the offset you supply. You must choose the correct offset for the date in question (for example, +1 vs +2 in Europe).
  • Assuming the clock time changes. The function attaches a zone label; it does not convert the time. Use DateTimeZone.ToUtc or DateTimeZone.SwitchZone to change the actual clock time.

Tips

  • Store offsets in a separate column or parameter so you can adjust them without editing the formula each time.
  • If your source data mixes zones, add a column with the correct offset per row and reference it as the second argument.
  • Use DateTimeZone.ToUtc immediately after adding the zone if your goal is a consistent UTC timeline for sorting or joining.
  • For display, keep the datetimezone type; Power Query and the data model preserve the offset information.
  • Test with a single row before applying to the whole column, especially when offsets include minutes.

Troubleshooting

If you see an error such as "We cannot convert the value to type DateTime," check the column type and convert text values first. If the new column shows only a date or time without an offset, set the column type to Date/Time/Timezone. If times appear shifted by the wrong amount, verify the sign and whether minutes are needed. If the formula returns null, the input may be null or an incompatible type; filter or replace nulls before the step. If Power Query rejects the formula, confirm you are using the correct function name and that the offset argument is a number, not text. When a step fails after a data refresh, check that the source column still exists and has the same name.

Frequently Asked Questions

Does DateTime.AddZone convert the time to another zone?

No. It attaches the offset you specify to the existing clock time. To change the clock time, use DateTimeZone.ToUtc or DateTimeZone.SwitchZone.

How do I handle daylight saving time?

You must supply the correct offset for the date. DateTime.AddZone does not apply time zone rules automatically, so use +1 or +2 (for example) depending on whether daylight saving is in effect.

Can I use a column for the offset instead of a fixed number?

Yes. The second argument can reference another column, such as [OffsetHours], as long as it contains numeric values.

What is the difference between DateTime.AddZone and DateTimeZone.SwitchZone?

DateTime.AddZone attaches a zone to a datetime without changing the clock time. DateTimeZone.SwitchZone changes the clock time to the new offset while keeping the same moment in time.

Why does my result show +00:00?

An offset of 0 was supplied, or the column type was set to UTC. Check the formula and the column type.

Does this work in Excel and Power BI?

Yes, DateTime.AddZone is part of the Power Query M language and works in both Excel and Power BI Desktop, as well as other hosts that support Power Query.