Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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"
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.
Solved! Go to Solution.
Something strange about your data or your system
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:
Something strange about your data or your system
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:
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:
Result:
Here's how to do it:
Select the column that contains the date/time values.
Click on the "Add Column" tab in the ribbon, and select "Custom Column" from the dropdown menu.
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.
Click "OK" to create the new column.
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.
Did I do something wrong?
please replace len by length
Still not working. ☹️ I don't think there's an M code len or length
please check https://learn.microsoft.com/fr-fr/powerquery-m/text-length Length capital case
I have a new error.
When I click the error it says: "Count Argument is out of range".
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the September 2025 Power BI update to learn about new features.