# Time and histories in Analytics

**URL:** https://forum.datomic.com/t/time-and-histories-in-analytics/1717
**Category:** Datomic Cloud
**Created:** [December 14, 2020, 4:45am UTC](https://forum.datomic.com/t/time-and-histories-in-analytics/1717 "2020-12-14T04:45:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hden](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/hden/32/388_2.png) [@hden](https://forum.datomic.com/u/hden)
#### Post date: [December 14, 2020, 4:45am UTC](https://forum.datomic.com/t/time-and-histories-in-analytics/1717/1 "2020-12-14T04:45:36Z")

</div>

In analytics, we often need to ask questions regarding an entity’s time, for example:

- when is the entity first seen in the system?
- when is the entity last touched?

In old-school sql, we might setup columns such as created\_at or updated\_at with trigger to ensure the values are accurate or an ORM might manage that for us. However, Datomic has a native history API that can help us answer the questions.

```
(defn created-at [db eid]
  (let [hist (d/history db)]
    (ffirst (d/q {:query '[:find (min ?inst)
                           :in $ ?e
                           :where [?e _ _ ?tx true]
                                  [?tx :db/txInstant ?inst]]
                  :args [hist eid]}))))

(defn updated-at [db eid]
  (ffirst (d/q {:query '[:find (max ?inst)
                         :in $ ?e
                         :where [?e _ _ ?tx]
                                [?tx :db/txInstant ?inst]]
                :args [db eid]})))))

```

Is there anyway I can expose them as a column in Analytics?

---

<div class="post-metadata">

### Author: ![jaret](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/jaret/32/45_2.png) [@jaret](https://forum.datomic.com/u/jaret)
#### Post date: [December 14, 2020, 1:59pm UTC](https://forum.datomic.com/t/time-and-histories-in-analytics/1717/2 "2020-12-14T13:59:28Z")

</div>

@hden We do not currently expose `t` to analytics. So you cannot expose these as columns for SQL queries. However, it is a feature we are looking at and was previously discussed on this forum post here: [How to limit the size of the result for analytics query](https://forum.datomic.com/t/how-to-limit-the-size-of-the-result-for-analytics-query/1647)

---

<div class="post-metadata">

### Author: ![husayn](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@husayn](https://forum.datomic.com/u/husayn)
#### Post date: [August 22, 2021, 11:12am UTC](https://forum.datomic.com/t/time-and-histories-in-analytics/1717/3 "2021-08-22T11:12:42Z")

</div>

@hden were you able to find a solution to this?

---

<div class="post-metadata">

### Author: ![hden](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/hden/32/388_2.png) [@hden](https://forum.datomic.com/u/hden)
#### Post date: [August 22, 2021, 11:58am UTC](https://forum.datomic.com/t/time-and-histories-in-analytics/1717/4 "2021-08-22T11:58:53Z")

</div>

Nope ☹
