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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Newbie22
Resolver I
Resolver I

How to change format from 2/14/23 to 2/14/2023 in Query Editor?

Hi All,

 

I have a data source that has a date&time column but the year is not complete. It's in text format and something like this "2/14/23 08:00:00 AM"

 

Newbie22_0-1676376027585.png

 

Is there anyway to change that into date/time column in Query Editor? Currently it's in text format but when I change it to date/time format It's giving an error because it does not recognize the year. I need to change the year (23) to a complete year (2023) but I don't know how to.

 

Hope I make sense. Thank you so much for your help.

 

 

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Something strange about your data or your system

  1. On my editor, those dates are automatically converted to the date of the current year.
  2. Power Query should be able to recognize years down to the year one (1) and should have no problem recognizing the year "23"
  3. Perhaps your system is not recognizing the "/" delimiter for dates

 

Suggest you try Changing Type with Locale

 

#"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Start Time", type datetime}}, "en-US")

 

or (from right-click on column menu:

ronrsnfld_0-1676404298872.png

 

View solution in original post

9 REPLIES 9
ronrsnfld
Super User
Super User

Something strange about your data or your system

  1. On my editor, those dates are automatically converted to the date of the current year.
  2. Power Query should be able to recognize years down to the year one (1) and should have no problem recognizing the year "23"
  3. Perhaps your system is not recognizing the "/" delimiter for dates

 

Suggest you try Changing Type with Locale

 

#"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Start Time", type datetime}}, "en-US")

 

or (from right-click on column menu:

ronrsnfld_0-1676404298872.png

 

Thank you @ronrsnfld. It worked! 😉

AlexisOlson
Super User
Super User

Odd. My Power BI works fine with both a type conversion and DateTime.FromText.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUorViVYy1LfUNzJWsLAyNbQyNlZw9IWIGukbmegbGSkYGloZWQKRQgBQIhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Time" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each DateTime.FromText([Start Time])),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Start Time", type datetime}})
in
    #"Changed Type"

 

Start:

AlexisOlson_1-1676403353763.png

 

Result:

AlexisOlson_0-1676403327941.png

jaweher899
Impactful Individual
Impactful Individual

Here's how to do it:

  1. Select the column that contains the date/time values.

  2. Click on the "Add Column" tab in the ribbon, and select "Custom Column" from the dropdown menu.

  3. In the formula bar, use the following formula to extract the year from the text:

    = DateTime.FromText("2/14/23 08:00:00 AM") + #duration(365*(Text.Range([Date&Time], Len([Date&Time])-1, 2)-1900),0,0,0)

    This formula uses the Text.Range function to extract the last two characters (which represent the year) from the text value, and then converts it to a datetime value by adding a duration to set the year.

  4. Click "OK" to create the new column.

  5. If necessary, you can then delete the original text column and rename the new column to match the original column name.

Note: The above formula assumes that the year is represented by the last two characters in the text format. If the year is represented differently, you may need to adjust the formula accordingly.

Thank you for your fast reply @jaweher899 

 

But I'm getting this error when I follow your code.

 

Newbie22_0-1676379686172.png

 

Did I do something wrong?

jaweher899
Impactful Individual
Impactful Individual

please replace len by length

Still not working. ☹️ I don't think there's an M code len or length 

 

Newbie22_3-1676380511972.png

 

 

Newbie22_1-1676380380932.png

 

jaweher899
Impactful Individual
Impactful Individual

I have a new error.

Newbie22_0-1676381611214.png

 

When I click the error it says: "Count Argument is out of range". 

Newbie22_1-1676381633056.png

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors