SQL Server UTC string comparison not working

后端 未结 1 1037
说谎
说谎 2021-01-28 09:42

we have two SQL Servers.

We have the following example SQL to recreate an issue we are facing.

select * from (

select \'2020-11-04 08:00:00\' as start
uni         


        
1条回答
  •  梦毁少年i
    2021-01-28 10:19

    I suspect the servers have different base languages/settings for dates - though obviously this is just a guess.

    One may consider 2020-11-04 08:00:00 as 8:00am on November 4, whereas the other treats it as 11 April.

    These can be based on

    • Windows regional settings
    • Default language of SQL Server

    You should use a universal datetime format e.g., 20201104 08:00:00. If you change the query above to use these, and the servers return the same answer as each other, I think you've found the issue.

    Of course, the servers could be in different timezones and/or haven't accounted for daylight savings - but SELECT getdate() should tell you what the server dates are.

    0 讨论(0)
提交回复
热议问题