# Badge for posts created between 1 AM and 5 AM

**URL:** https://meta.discourse.org/t/badge-for-posts-created-between-1-am-and-5-am/178826
**Category:** Development
**Tags:** badges
**Created:** [February 7, 2021, 10:41pm UTC](https://meta.discourse.org/t/badge-for-posts-created-between-1-am-and-5-am/178826 "2021-02-07T22:41:52Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![michebs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michebs/32/190102_2.png) [@michebs](https://meta.discourse.org/u/michebs)
#### Post date: [February 8, 2021, 7:41pm UTC](https://meta.discourse.org/t/badge-for-posts-created-between-1-am-and-5-am/178826/10 "2021-02-08T19:41:30Z")

</div>

> [@cosdesign](#):
>
> is it possible to have that time check based on the user’s chosen time on his profile?

Considering the user’s timezone, the query will look like this:

```sql
WITH users_timezone AS (
    SELECT 
        user_id, 
        CASE WHEN utc_offset IS NULL THEN '00:00:00' 
             ELSE utc_offset END
    FROM user_options uo
    LEFT JOIN pg_timezone_names pt ON uo.timezone = pt.name
)

SELECT 
    p.user_id,
    current_timestamp granted_at
FROM badge_posts p  
INNER JOIN users_timezone ut ON ut.user_id = p.user_id
WHERE (p.created_at+ut.utc_offset)::time BETWEEN '01:00' AND '05:00'
GROUP BY p.user_id 
HAVING count(*) >= 100

```

---

_[View the full topic](https://meta.discourse.org/t/badge-for-posts-created-between-1-am-and-5-am/178826)._
