# Adding a date parameter

**URL:** <https://meta.discourse.org/t/adding-a-date-parameter/276158>\
**Category:** Data & reporting\
**Tags:** sql-tutorial\
**Created:** [August 22, 2023, 9:18am UTC](https://meta.discourse.org/t/adding-a-date-parameter/276158 "2023-08-22T09:18:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [August 22, 2023, 1:10pm UTC](https://meta.discourse.org/t/adding-a-date-parameter/276158/3 "2023-08-22T13:10:09Z")

</div>

Ah yes, it doesn’t like those inline comments next the parameters.

```sql
-- [params]
-- date :start_date 
-- date :end_date 

SELECT
   t.category_id,
   COUNT(p.id) AS "Total Posts" -- Count the number of posts in each category
FROM posts p 
  JOIN topics t ON t.id = p.topic_id 
WHERE p.created_at::date BETWEEN :start_date AND :end_date -- Filter posts that were created between the start date and the end date (::date casts the created_at timestamp as a date)
  AND t.deleted_at IS NULL 
  AND p.deleted_at IS NULL 
  AND t.archetype <> 'private message' 
  AND p.user_id > 0
  AND t.category_id IS NOT NULL 
GROUP BY 1 
ORDER BY 2 DESC

```

This one seems to work better. 👍 (You may need to refresh the page the first time to pick up the parameter input boxes)

Thanks for helping me de-bug the guides. 🙂 🏆

---

_[View the full topic](https://meta.discourse.org/t/adding-a-date-parameter/276158)._
