cancel
Showing results for 
Search instead for 
Did you mean: 
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

3 REPLIES 3
Phil_Seamark
Microsoft
Microsoft

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?

View solution in original post

Date format is DateTime only set to midnight.


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

Proud to be a Datanaut!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors