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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Change datetime format to date in SQL

Hi,

 

I was trying to change the datetime format to date in the SQL statement in order to lessen the M query due to connecting to a huge database.

Here is my code: convert(date, createTime, 101), but turned out error. What is the appropriate command for it?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Phil_Seamark,

 

The createtime column is in datetime format.

Only the cast(createtime as date) works for me. The result is in the format of datetime too.

datetime.JPG

 

Is that possible to direct convert it to date format without using query M?

View solution in original post

5 REPLIES 5
Phil_Seamark
Microsoft Employee
Microsoft Employee

What is the datatype for your createTime column in SQL?  Is it a Date-Time column or a character based data type (Char/NChar?)

 

you could try the following

 

CAST(createTime AS Date)

 

 

or

 

convert(date, createTime, 103)

or

 

TRY_CAST(createTime AS Date)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

@Phil_Seamark,

 

The createtime column is in datetime format.

Only the cast(createtime as date) works for me. The result is in the format of datetime too.

datetime.JPG

 

Is that possible to direct convert it to date format without using query M?

Date format is DateTime only set to midnight.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

That's obvious and is clearly not the question.

 

You are aware that in M there's a data type Date that removes the Time component completely? So why when in SQL you explicitly CAST DateTime as DATE PowerQuery is not picking it up as Date data type but instead is treating it as DateTime with 00:00:00 in the time part? It looks ugly and is confusing.

Any updates on this or do I have to explicitly FIX every date column in Power BI?  It's a complete pain when you've already specified it as a DATE data type in Microsoft SQL Server. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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