Forum Discussion
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?
- Anonymous8 years ago
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.
Is that possible to direct convert it to date format without using query M?
5 Replies
- Phil_SeamarkMicrosoft 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)
- AnonymousNot applicable
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.
Is that possible to direct convert it to date format without using query M?
- Phil_SeamarkMicrosoft Employee
Date format is DateTime only set to midnight.