# SQL query in Data Explorer to pull latest topics?

**URL:** <https://meta.discourse.org/t/sql-query-in-data-explorer-to-pull-latest-topics/63908>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [June 4, 2017, 3:47pm UTC](https://meta.discourse.org/t/sql-query-in-data-explorer-to-pull-latest-topics/63908 "2017-06-04T15:47:22Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![sunnyt7](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sunnyt7/32/71920_2.png) [@sunnyt7](https://meta.discourse.org/u/sunnyt7)\
**Post date:** [June 6, 2017, 3:20am UTC](https://meta.discourse.org/t/sql-query-in-data-explorer-to-pull-latest-topics/63908/9 "2017-06-06T03:20:30Z")

</div>

Wohoo, just figured out how to get the “8 hours ago” using the Twig Syntax:

```
{% set difference = date("now"|date("M j, g:ia T")).diff(date(row[11]|date("M j, g:ia T"))) %}
{% set leftDays = difference.days %}
{% set leftHours = difference.h %}
{% set leftMinutes = difference.i %}
{% if leftDays > 1 %}
  {{ leftDays }} days
{% elseif leftDays == 1 %}
  {{ leftDays }} day
{% elseif leftHours > 1 %}
  {{ leftHours }} hours {{ leftMinutes }} min
{% elseif leftHours == 1 %}
  {{ leftHours }} hour {{ leftMinutes }} min
{% else %}
  {{ leftMinutes }} min
{% endif %}

```

Now looking something like:

 ![](https://global.discourse-cdn.com/meta/original/3X/0/8/082551272816809a58409cf38aac5f3588f9838e.png)

---

_[View the full topic](https://meta.discourse.org/t/sql-query-in-data-explorer-to-pull-latest-topics/63908)._
