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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
TeisL
Frequent Visitor

Powerquery US date Text to DateTime format

Hi everyone,

 

I want to transform a text value (MM/DD/YYY hh:mm:ss) into a datetime (DD/MM/YYYY hh:mm:ss) value.

Example of the data:

Created dateNew date
3/7/2019 1:25:03 PM7/3/2019 13:25:03
3/18/2019 8:22:38 AM18/3/2019 8:22:38

 

 

Thanks you so much!

3 REPLIES 3
ronrsnfld
Super User
Super User

You only need to tell Power Query the format of the text date.

If you want to add a column as you show in your example, then:

 

 

let
    Source = Table.FromColumns(
        {{"3/7/2019 1:25:03 PM","3/18/2019 8:22:35 AM"}},
        type table[Created date=text]
    ),
    #"Added Custom" = Table.AddColumn(Source, "New date", each DateTime.From([Created date],"en-US"), type datetime)
in
    #"Added Custom"

 

 

If you want to transform it in place, you can use the Change Type Using Locale from the right click dropdown on that column, and select DateTime and United States.

ronrsnfld_1-1703036600657.png

 

 

let
    Source = Table.FromColumns(
        {{"3/7/2019 1:25:03 PM","3/18/2019 8:22:35 AM"}},
        type table[Created date=text]
    ),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Created date", type datetime}}, "en-US")
in
    #"Changed Type with Locale"

 

 

In the Power Query editor, the date will be displayed according to your Windows Regional Settings.

In Power BI, you can set the format of that column however you wish.

collinsg
Solution Sage
Solution Sage

Good day TeisL,

You can use the DateTime.FromText() function. It has an optional parameter to specify the format of the input text and an optional parameter to specify the format of the output datetime, for example.

DateTime.FromText( [Datetime as Text], [Format="M/d/yyyy h:mm:ss tt", Culture="en-UK"] )

The following is an example using your dates. The first step, "Source" reproduces your table of datetimes in text format. The second step adds a column with "Created Date" converted to datetime in your desired format.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY31zcyMLRUMLQyMrUyMFYI8FWK1QGJG1pAJCysjIysjC0UHIESsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Created Date" = _t]),
#"Convert from text" = Table.AddColumn(Source, "Datetime", each DateTime.FromText( [Created Date], [Format="M/d/yyyy h:mm:ss tt", Culture="en-UK"] ), type datetime)
in
#"Convert from text"

Hope this helps.

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @TeisL ,

 

How about this:

tackytechtom_0-1702925944419.png

 

Here the Power Query M code for the new custom column:

try DateTime.FromText(
    Text.Split( Text.From( [date]), " " ){0} &" "&Text.Split( Text.From( [date]), " " ){1},[Format = "MM/dd/yyyy h:mm:ss"]) otherwise
    try DateTime.FromText(
    Text.Split( Text.From( [date]), " " ){0} &" "&Text.Split( Text.From( [date]), " " ){1},[Format = "M/dd/yyyy h:mm:ss"]) otherwise
    try DateTime.FromText(
    Text.Split( Text.From( [date]), " " ){0} &" "&Text.Split( Text.From( [date]), " " ){1},[Format = "MM/d/yyyy h:mm:ss"]) otherwise
   DateTime.FromText(
    Text.Split( Text.From( [date]), " " ){0} &" "&Text.Split( Text.From( [date]), " " ){1},[Format = "M/d/yyyy h:mm:ss"])

 

Note, I called the original column "date". You need to align the code accordingly. 

 

Also, I took the code from here and aligned it a bit:

Converting dates from MM/DD/YYYY to DD/MM/YYYY in ... - Microsoft Fabric Community

 

Hope this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.