# Active users in the last 30 days

**URL:** https://meta.discourse.org/t/active-users-in-the-last-30-days/275140
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [August 30, 2016, 6:38pm UTC](https://meta.discourse.org/t/active-users-in-the-last-30-days/275140 "2016-08-30T18:38:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [August 30, 2016, 6:38pm UTC](https://meta.discourse.org/t/active-users-in-the-last-30-days/275140/1 "2016-08-30T18:38:58Z")

</div>

### Active users in the last 30 days

```sql
select username
from users
where last_posted_at > current_timestamp - interval '30' day

```

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [September 5, 2016, 5:46pm UTC](https://meta.discourse.org/t/active-users-in-the-last-30-days/275140/2 "2016-09-05T17:46:08Z")

</div>

How would you adjust this with parameters so that previous months can also be checked? Eg: read between 62 and 31 days ago (or similar)?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [September 5, 2016, 6:19pm UTC](https://meta.discourse.org/t/active-users-in-the-last-30-days/275140/3 "2016-09-05T18:19:17Z")

</div>

I haven’t figured out a “between” way of doing this, but using “params” can provide a selectable “back to”

```plaintext
-- [params]
-- int :interval = 30

select username
from users
where last_posted_at > current_timestamp - interval ':interval' day

```

---

<div class="post-metadata">

### Author: ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)
#### Post date: [September 5, 2016, 9:47pm UTC](https://meta.discourse.org/t/active-users-in-the-last-30-days/275140/4 "2016-09-05T21:47:07Z")

</div>

should be able to do something like this (starting where @Mittineague left off):

```plaintext
-- [params]
-- int :until_days_ago = 30
-- int :since_days_ago = 60

select username
from users
where last_posted_at > current_timestamp - interval ':since_days_ago' day 
and last_posted_at < current_timestamp - interval ':until_days_ago' day

```
