Fork me on GitHub

A colleague of mine noticed that dates on our MSSQL server are interpreted relative to the timezone of the client:

    (TimeZone/setDefault (TimeZone/getTimeZone "Europe/Copenhagen"))
    (jdbc/query conn "select getdate() as now"))
  ;; => ({:now #inst"2018-02-25T20:56:12.227000000-00:00"})

    (TimeZone/setDefault (TimeZone/getTimeZone "UTC"))
    (jdbc/query conn "select getdate() as now"))
  ;; => ({:now #inst"2018-02-25T21:56:29.427000000-00:00"})
We can mitigate this by setting the timezone of the client to that of the server: (TimeZone/setDefault (TimeZone/getTimeZone "<server timezone>")). Is there any way of making this approach thread safe?


@grav Timezones are very problematic with databases -- the only really sane option is to have all your servers and all your software running in UTC and translate to/from the end user TZ at the edges.