Convert Data Sqlserver

Asked

Viewed 67 times

1

I would like to convert02/01/2018 for 2018-01-02 00:00:00.000, what I found on the internet so far was:

select CONVERT (datetime, '02/01/2018', 120) 

Who returns to me2018-02-01 00:00:00.000, a little different than what I need.

What number should I use instead of the 120?

  • 2

    Check date and time styles at https://docs.microsoft.com/pt-br/sql/t-sql/functions/cast-and-convert-transact-sql

2 answers

3


According to that answer of the SO, the code you want is the 103:

select CONVERT (datetime, '02/01/2018', 103)

-2

108 back the hours too.

SELECT CONVERT (DATETIME, '02/01/2018', 103) + ' ' + CONVERT(VARCHAR, nomedacoluna, 108)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.