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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
llyons
Frequent Visitor

convert DateTime format from dd/mm/yyyy hh:mm:ss AM to hh:mm:ss

Hello,

Please let me know how to convert a DateTime format from dd/mm/yyyy hh:mm:ss AM to hh:mm:ss in Power Query Editor.

 

I uploaded call center data from excel and the data importe example  12/31/1899 12:01:26 AM instead of 00:01:26 for AHT. I will need to show (1)  line chart for each interval of the day and (2) a chart with the aggregated AHT for a line of business.

 

I have Power BI professional not sure what version. I was able to update from Power BI desktop to Pro this year.

 

I tried this using using this formula HOUR([AHT])*3600+MINUTE([AHT])*60+SECOND([AHT]) but I received an error

9 REPLIES 9
Alphatooth
Frequent Visitor

Also, can we convert dd/mm/yyyy hh:mm:ss AM/PM to hh AM/PM to plot a 24 hour timeline.

mahoneypat
Microsoft Employee
Microsoft Employee

You can convert it to a duration with 

= [DateTimeColumn] - #datetime(1899,12,31,0,0,0)

 

But to do math with that column, you should wrap that in Duration.TotalHours (other related functions too).

 

= Duration.TotalHours([DateTimeColumn] - #datetime(1899,12,31,0,0,0))

 

You will get the hours in decimal form so you can add them up, average, etc.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


PC2790
Community Champion
Community Champion

Hi @llyons ,

 

Two ways to do it:

1) Create a new custom column using the below M query:

= DateTime.ToText([Date],"hh:mm:ss")

 

My code looked something like this:

= Table.AddColumn(#"Changed Type2", "Date Format", each DateTime.ToText([Date1],"hh:mm:ss"))

 

2) The second way is in the main Power Bi desktop. Steps below:

      a) Convert the column into 'Time' DataType

      b) In ColumTools, select the format that you want. Screenshot for your help below:

 

PC2790_0-1610513718926.png

Let me know if it solves your purpose. 

Please mark this as solution if this was exactly you were looking for

PC2790
Community Champion
Community Champion

Hi @llyons ,

 

There are two ways to do it:

1)You can split the date and time in Power query by clicking on the column --> Split --> By delimiter --> select space

This will give you two columns with date and time separately. 

The corresponding M query will be something like:

= Table.SplitColumn(#"Table", "DateTime", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Date", "Time"})

2) The second way is to right click and change the data type to time instead of DateTime. The corresponding M query code is as below:

= Table.TransformColumnTypes(#"Table",{{"DateTime", type time}}) 

 

I would recommend to take appraoch 1 as it will enable you to retain the date data for future use.

 

Let me know if this is what you were looking for.

 

Thankyou

llyons
Frequent Visitor

when I use your suggestion I cannot show the time in a chart or add to create a total for a particular month.

llyons
Frequent Visitor

Thank you for your responds.

When I split the column my time example is 12:01:26 AM  .  I need  the result to show 00:01:26 because it is not 12 hours nor do I need the AM.  Is there a DAX code I could use?

 

jbwtp
Memorable Member
Memorable Member

I think this is rather Column Tools -> Format

jbwtp_0-1666907200578.png

You should not need any DAX for that.

But I don't see hh AM/PM choice. Any idea on how we can achieve this ?

For example:

DAX (as custom column)

 

Column = FORMAT('Table'[Time], "hh AM/PM")

 

Do not forget to set sorting for [Column] by [Time] in the Column tools menu.

 

Do you alsowant to show 12 AM as 0AM?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.