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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
mcflurry
Helper I
Helper I

Convert string to date

Hello guys,

 

I have a string column with this:

 

20220307-06:30:06-GMT+0100

 

I'm trying to convert it to a date column without success.

How could it be done?

2 ACCEPTED SOLUTIONS
vojtechsima
Super User
Super User

Hi, @mcflurry 
In Power Query with TimeZone:

vojtechsima_0-1646660276179.png

 

 

 

let
Date = Date.FromText(Text.BeforeDelimiter(Text.ReplaceRange([String],8,1,"T"),"T")),
Time = Time.FromText(Text.BetweenDelimiters([String], "-", "-")),
getTimeZone = Text.AfterDelimiter([String], "T"),
getPlusOrMinusZone = Text.Start(getTimeZone, 1),
GetHourOfZone = Number.FromText( Text.Middle(getTimeZone,1,2)),
GetMinuteOfZone = Number.FromText(Text.End(getTimeZone,2)),
DateTime = DateTime.From(Date & Time),
DateTimeZone = DateTime.AddZone(DateTime,GetHourOfZone,GetMinuteOfZone),
CompleteWithCheck = if getPlusOrMinusZone = "+" then DateTimeZone else DateTime.AddZone(DateTime,-GetHourOfZone,GetMinuteOfZone)

in CompleteWithCheck

 

 

Add New Column like this. "String" is your column with the provided date. Then just Change Type of the new column to "date" or "datetime" or "datetimezone".

Edit:
I enhanced the code to check whether it's "+" or "-".






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

View solution in original post

Regional Settings is already to an European country.

 

Could you please help me on how to fix it with your code?

I guess it's this line, but i don't have the knowledge to achieve it... 

 

Date = Date.FromText(Text.BeforeDelimiter(Text.ReplaceRange([String],8,1,"T"),"T")),

 

I'm transforming the the original column with unicode format... and maybe it will work.

Yep, fixed that way, thanks.

View solution in original post

4 REPLIES 4
vojtechsima
Super User
Super User

Hi, @mcflurry 
In Power Query with TimeZone:

vojtechsima_0-1646660276179.png

 

 

 

let
Date = Date.FromText(Text.BeforeDelimiter(Text.ReplaceRange([String],8,1,"T"),"T")),
Time = Time.FromText(Text.BetweenDelimiters([String], "-", "-")),
getTimeZone = Text.AfterDelimiter([String], "T"),
getPlusOrMinusZone = Text.Start(getTimeZone, 1),
GetHourOfZone = Number.FromText( Text.Middle(getTimeZone,1,2)),
GetMinuteOfZone = Number.FromText(Text.End(getTimeZone,2)),
DateTime = DateTime.From(Date & Time),
DateTimeZone = DateTime.AddZone(DateTime,GetHourOfZone,GetMinuteOfZone),
CompleteWithCheck = if getPlusOrMinusZone = "+" then DateTimeZone else DateTime.AddZone(DateTime,-GetHourOfZone,GetMinuteOfZone)

in CompleteWithCheck

 

 

Add New Column like this. "String" is your column with the provided date. Then just Change Type of the new column to "date" or "datetime" or "datetimezone".

Edit:
I enhanced the code to check whether it's "+" or "-".






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

Hello @vojtechsima 

I have a problem with your code.

It looks like it's taking the day as month and the month as day, and imported data from yesterday fails, i've tried with 02/28 as an example:

 

mcflurry_0-1647348385236.png

 

Hi, @mcflurry 
Go to Settings - Regional Settings (current file) and change it to some European country, in my case Czech Republic, or rewrite the script that it first writes month and then day.






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

Regional Settings is already to an European country.

 

Could you please help me on how to fix it with your code?

I guess it's this line, but i don't have the knowledge to achieve it... 

 

Date = Date.FromText(Text.BeforeDelimiter(Text.ReplaceRange([String],8,1,"T"),"T")),

 

I'm transforming the the original column with unicode format... and maybe it will work.

Yep, fixed that way, thanks.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.