Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Converting Time Zones

Hello everyone,

 

I have a table like the below:

What I need to do is to add column that keeps the same Due Time if Timing is Cairo and change the Due Time if the the Timing is Edinburgh to convert it to Cairo time, bearing in mind the DST that is applied in UK but not in Egypt (not anymore).

 

 

Due TimeTiming

6:00:00 PMCairo
5:00:00 PMEdinburgh
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

TimeZone conversions can be tricky, especially when DST applies. Unfortunately, there is not a good way to directly convert a DateTime to another zone (factoring in DST). However, there are free Rest APIs you can use that don't require an API key (and more free ones that do).  Here are two examples.

 

If you only need to convert a time on today's date, you can simply get the offset value with this expression. You can remove the [utc_offset] part to see what other info is there. You can then use another function to add hours or switchzone by that number of hours (after you convert it to a number).

 

= Json.Document(Web.Contents("http://worldtimeapi.org/api/timezone/Africa/Cairo"))[utc_offset]

 

If you have a column of past/future datetimes and need to convert them (accounting for DST), you can use this function I wrote that uses a different REST API.

 

//fnConvertTimeZone

(dt as text, fromZone as text, toZone as text) =>
let
BaseURL = "https://www.timeapi.io/api/Conversion/ConvertTimeZone",
headers = [#"Content-Type" = "application/json"],
Body = [dateTime = dt, fromTimeZone = fromZone, toTimeZone = toZone, dstAmbiguity=""],
Response = Web.Contents(BaseURL, [Headers = headers, Content = Json.FromValue(Body)]),
Result = Json.Document(Response)[conversionResult][dateTime]
in
Result

 

You can then Invoke Custom Column passing in your DateTime and zone info like this. I named the function fnConvertTimeZone. There is likely a limit on this API, so it may not work with too many rows.

 

= fnConvertTimeZone("2021-03-14 17:45:00", "Europe/Dublin", "Africa/Cairo")

 

or with a column reference (with the text formatted as shown above)

 

= fnConvertTimeZone([DateTime Column], "Europe/Dublin", "Africa/Cairo")

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

TimeZone conversions can be tricky, especially when DST applies. Unfortunately, there is not a good way to directly convert a DateTime to another zone (factoring in DST). However, there are free Rest APIs you can use that don't require an API key (and more free ones that do).  Here are two examples.

 

If you only need to convert a time on today's date, you can simply get the offset value with this expression. You can remove the [utc_offset] part to see what other info is there. You can then use another function to add hours or switchzone by that number of hours (after you convert it to a number).

 

= Json.Document(Web.Contents("http://worldtimeapi.org/api/timezone/Africa/Cairo"))[utc_offset]

 

If you have a column of past/future datetimes and need to convert them (accounting for DST), you can use this function I wrote that uses a different REST API.

 

//fnConvertTimeZone

(dt as text, fromZone as text, toZone as text) =>
let
BaseURL = "https://www.timeapi.io/api/Conversion/ConvertTimeZone",
headers = [#"Content-Type" = "application/json"],
Body = [dateTime = dt, fromTimeZone = fromZone, toTimeZone = toZone, dstAmbiguity=""],
Response = Web.Contents(BaseURL, [Headers = headers, Content = Json.FromValue(Body)]),
Result = Json.Document(Response)[conversionResult][dateTime]
in
Result

 

You can then Invoke Custom Column passing in your DateTime and zone info like this. I named the function fnConvertTimeZone. There is likely a limit on this API, so it may not work with too many rows.

 

= fnConvertTimeZone("2021-03-14 17:45:00", "Europe/Dublin", "Africa/Cairo")

 

or with a column reference (with the text formatted as shown above)

 

= fnConvertTimeZone([DateTime Column], "Europe/Dublin", "Africa/Cairo")

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Wait! It actually worked even with a column of dates and with the DST

It just didn't work with Europe/Edinburgh, I don't know why, but Europe/Dublin is just fine, I guess, thanks a million, you're a great help.

Anonymous
Not applicable

Well, the problem is, it is not for today only, there is a column for the date that got dates list for years.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.