This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-16
Channels
- # aleph (2)
- # announcements (1)
- # aws (2)
- # babashka (5)
- # beginners (122)
- # boot-dev (1)
- # cider (3)
- # clara (7)
- # cljdoc (11)
- # clojure (161)
- # clojure-dev (45)
- # clojure-europe (8)
- # clojure-france (1)
- # clojure-india (1)
- # clojure-italy (3)
- # clojure-nl (11)
- # clojure-uk (34)
- # clojurebridge (2)
- # clojurescript (13)
- # cryogen (10)
- # cursive (13)
- # datomic (25)
- # emacs (8)
- # fulcro (76)
- # graalvm (2)
- # jackdaw (5)
- # jobs-discuss (2)
- # juxt (13)
- # off-topic (13)
- # pathom (5)
- # pedestal (7)
- # quil (2)
- # reitit (9)
- # remote-jobs (4)
- # schema (1)
- # shadow-cljs (33)
- # spacemacs (8)
- # sql (9)
- # vim (2)
- # vrac (2)
(jt/format (jt/instant->sql-timestamp (jt/truncate-to (jt/instant (* 1578830944 1000)) :days))) => "2020-01-12 03:00:00.0"
I am trying to convert a given unix time in seconds to a sql date string. In the above code I am truncating the hours part, but when I convert it into string it shows an hour part, what am I doing wrong ?
Timezones, I would assume.
Instants are UTC. Converting to a SQL timestamp is local time.
When I run that code, I see different hours because I'm in a different TZ to you
user=> (jt/format (jt/instant->sql-timestamp (jt/truncate-to (jt/instant (* 1578830944 1000)) :days)))
"2020-01-11 16:00:00.0"
@seancorfield thanks, had missed that.
just fyi, this worked with timezone offset-
(jt/format
(jt/sql-timestamp
(jt/truncate-to
(java.time.LocalDateTime/ofInstant (jt/instant (* 1578830944 1000)) (java.time.ZoneOffset/ofTotalSeconds 7200))
:days)))
@murtaza52 Bear in mind that will work for your machine on your timezone -- be careful about running that code on other machines that may be on different timezones.
We have all our servers set to UTC and we have our databases set to UTC. Timezones are a giant pain to deal with.