Fork me on GitHub
Nedeljko Radovanovic21:08:06

Hi guys, I need to retrieve id's from all users in database that are older then 30 days, every user has creation date.,

(let [conn (client/get-conn)
      db (client/db)
      last-month (t/minus (t/now) (t/month 1))
      q '{:find  [(pull ?eid [*])]
          :where [[?eid :user/created]]}]
I have last-month #inst date, I just dont know how to get all users "older" then 30 days. I am new in datomic so, if someone can help, thank you in advance...


(let [conn (client/get-conn)
      db (client/db)
      ;; using java.time
      #_#_last-month (Date/from (.minus (Instant/now)
                                  (Duration/ofDays 30)))
      last-month (t/minus (t/now) (t/month 1))]
  ;; get the created from the instant where user/id was created
  #_(d/q '{:find  [(pull ?eid [*])]
           :in    [$ ?last-month]
           :where [[?eid :user/id _ ?tx]
                   [?tx :db/txInstant ?created]
                   [< ?created ?last-month]]}
      db last-month)
  (d/q '{:find  [(pull ?eid [*])]
         :in    [$ ?last-month]
         :where [[?eid :user/created ?created]
                 [< ?created ?last-month]]}
    db last-month))


IDK what t/minus returns, but d/q requires something that look like a java.util.Date

Nedeljko Radovanovic10:08:51

it returns a instance like this #<DateTime 1986-10-14T04:00:00.000Z>

Nedeljko Radovanovic10:08:44

i am saving creation date as Date instance so this solution works best right now, if i didnt have this solution i would need to change how create time is written in database, and to replace (new Date) with (t/now)

Nedeljko Radovanovic10:08:19

last-month (t/minus (t/now) (t/month 1))
this is from clj-time library