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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to convert "img_2016-12-16_11:30:35" as datetime?

I have column "img_2016-12-16_11:30:35" in Power BI. How to convert this column to datetime format?

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

Hi @Anonymous,

In your scenario, you can also create the following new columns to split your original column.

SplitColumn = REPLACE(Table2[Column1],1,4,"")
ReplaceColumn = SUBSTITUTE(Table2[SplitColumn],"_"," ")
1.PNG

Then select the ReplaceColumn  in Fields Panel, change its data type to Date/Time under modeling ribbon.
2.PNG3.PNG



Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yuezhe-msft
Employee
Employee

Hi @Anonymous,

In your scenario, you can also create the following new columns to split your original column.

SplitColumn = REPLACE(Table2[Column1],1,4,"")
ReplaceColumn = SUBSTITUTE(Table2[SplitColumn],"_"," ")
1.PNG

Then select the ReplaceColumn  in Fields Panel, change its data type to Date/Time under modeling ribbon.
2.PNG3.PNG



Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BhaveshPatel
Community Champion
Community Champion

You can use Replace Values & split column functionality to convert to date time format.

Firstly, Replace _ by space using replace values functionality.

then you can use split column by firstly 4 characters from left side and then split column by 1 character from right side. 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WilHKzE2PNzIwNNM1NNI1NIs3NLQyNrAyNo1RUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [col1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","_"," ",Replacer.ReplaceText,{"col1"}),
#"Split Column by Position" = Table.SplitColumn(#"Replaced Value","col1",Splitter.SplitTextByPositions({0, 4}, false),{"col1.1", "col1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"col1.1", type text}, {"col1.2", type text}}),
#"Split Column by Position1" = Table.SplitColumn(#"Changed Type1","col1.2",Splitter.SplitTextByPositions({0, 1}, true),{"col1.2.1", "col1.2.2"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Position1",{{"col1.2.1", type datetime}, {"col1.2.2", type text}})
in
#"Changed Type2"

 

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.