Fork me on GitHub
#sql
<
2018-02-25
>
grav21:02:56

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

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

  (do
    (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?

seancorfield21:02:02

@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.