Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
I have a table with timestamped data of datatype datetimezone, eg. 07-08-2020 08:00:00 + 02:00.
How do I convert this to datetime in a way that takes tz info into account, eg. 07-08-2020 10:00:00?
Note that the + 02:00 part has been added to the timestamp, not simply stripped away.
If I try to manually convert the datatype, I get an error.
Cheers, Mike
EDIT: I've just noticed that this is almost 5 years old topic, but maybe it will help to someone...
Hi @h4tt3n, check this:
let
Source = #table(null, {{"07-08-2020 08:00:00 +02:00"}}),
Ad_CorrectDateTime = Table.AddColumn(Source, "CorrectDateTime", each let a = DateTimeZone.From([Column1]) in DateTime.From(a) + #duration(0, DateTimeZone.ZoneHours(a), DateTimeZone.ZoneMinutes(a), 0), type datetime)
in
Ad_CorrectDateTime
If there is a space after + sign (as you showed us in your sample) use this:
let
Source = #table(null, {{"07-08-2020 08:00:00 + 02:00"}}),
Ad_CorrectDateTime = Table.AddColumn(Source, "CorrectDateTime", each let a = DateTimeZone.From(Text.Combine(Text.Split([Column1], " + "), " +")) in DateTime.From(a) + #duration(0, DateTimeZone.ZoneHours(a), DateTimeZone.ZoneMinutes(a), 0), type datetime)
in
Ad_CorrectDateTime
Unsure if this is helpful to anyone. I was finding the solution getting the most kudos was substracting the timezone and this was the opposite of I wanted it. I ended up just making this stupidly long calculation instead:
if [DateTimeZone] is null then null else
DateTime.From(Text.BeforeDelimiter(Text.From([DateTimeZone], "en-AU"), "+"))
+
#duration(0,
Time.Hour(Time.From(Text.AfterDelimiter(Text.From([DateTimeZone], "en-AU"), "+"))),
Time.Minute(Time.From(Text.AfterDelimiter(Text.From([DateTimeZone], "en-AU"), "+"))),
Time.Second(Time.From(Text.AfterDelimiter(Text.From([DateTimeZone], "en-AU"), "+"))))
First part just makes sure the value isn't null.
Then it extracts the text before the delimiter "+" which in my case is the datetime, then adds the text after the "+" delimiter which is my timezone information.
Not exactly convient but does the job.
Don't forget to convert the column to a datetime once done.
First convert column to Date/Time/Zone and then here's my solution in PowerQuery:
Table.TransformColumns(#"PREVIOUS STEP NAME",{{"FIELD NAME", each if _=null then null else DateTime.From(_)+#duration(0,Number.From(Text.Start(Text.End(Text.From(_),6),3)),0,0), type datetime}})
Hi @h4tt3n ,
You can acheive this by splitting the column.Below i have attached the screenshots for your understanding.
This is your orignal column with Datetimezone
Split Column
Split column:
Select or enter delimeter : Custom
Use +
Split at: Left-most delimeter
Click on OK
Result :
Result,which is a datetime datatype.
If your problem is solved please accept this as solution.
Thank you
orry, this simply discards timezone info, it doesn't incorporate it into the time. However, I have found the solution with a python script.
Hi, Can you share the steps you used to add the timestamp to the date using python
@Macc-PA I think this is the script. After all, it's one year ago, and we ended up not using it anyway.
Thanks for that - in the end we didnt need to use it.
The problem was solved by ensuring our odata datasource was sending the datetime as UTC, ie not converting it to local time.
Once that happened, converting the column to DataTime applied the UTC offset as expected even for datetimes where daylight saving was involved.
In effect you are asking to convert a datetimezone value to a datetime in UTC:
let
dtz = ...,
udtz = DateTimeZone.SwitchZone(dtz, 0),
dt = DateTimeZone.RemoveZone(udtz)
in
dt
Hi @h4tt3n
Convert into datetime but add another step
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDXNbDQNTIwMlAwsLAyMAAiBW0DIyClFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type datetimezone}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Column1", type datetime}})
in
#"Changed Type1"
I have tried to add the conversion as another step, but unfortunately this doesn't work either. Challenge remains unsolved.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
13 | |
12 | |
8 | |
8 |
User | Count |
---|---|
17 | |
10 | |
7 | |
7 | |
7 |