SQL is importing dates in different format

Asked

Viewed 80 times

3

I am having problems when selecting a date column in SQL Server. It turns out that my data is in format dd/mm/aaaa and when I select this column the SQL reverses getting aaaa-dd-mm and it actually had to be aaaa-mm-dd.

This happens on some dates like 02/12/2014 he converts as 2014-02-12. The type of column is datetime2(7)

  • This is the standard format of the bank, I believe that there is no way you can change this and nor should you. This formatting should be done in the application.Use the date classes that exist in many languages for this, so you don’t have to keep converting by hand.

  • Which version of SQL Server and which column type?

  • SQL Server 2012 and column type is datetime2(7)

  • Kleber, when answering someone in the comments, remember to quote the person you are responding to, or they will not be notified of your response. I believe you answered @rray’s question

  • 1

    take a look at this example http://answall.com/questions/58521/como-saber-qual-formato-de-datetime-utilizado-em-determinada-coluna-do-sql-serve/58546#58546

1 answer

3

When you perform SELECT use the following syntax:

SELECT CONVERT(VARCHAR(23), GETDATE(), 121)

Replace function getdate() by the name of the column you want to convert.

  • This is valid for type datetime2(7)? or for Datetime?

  • 1

    @Marconcilio Souza can use with both the result will be the same, you can test this way: SELECT CONVERT(VARCHAR(23), SYSDATETIME(), 121) sysdatetime returns a datetime2

Browser other questions tagged

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