Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

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?

 

  • Anonymous's avatar
    Anonymous
    8 years ago

    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.

     

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

5 Replies

  • Phil_Seamark's avatar
    Phil_Seamark
    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)
    • Anonymous's avatar
      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.

       

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